You can pass your parameters as a keyword arguments: -
def __init__(self, **kwargs):
self.args = kwargs
Then you will instantiate your class like this: -
myClassObj = MyClass(a=12, b="abc")
Then your args dict will contain those arguments as key-value pair: -
{'a':12, 'b':'abc'}
to access the attributes: -
myClassObj.args['a']
myClassObj.args['b']
You can also pass a combination of various arguments. There are 4 kinds of arguments you can have in any function: -
- Positional Argument
- Default Argument
- Non-Keyword Argument
- Keyword argument.
In that order only. So the typical syntax of a function declaration is: -
def func(positional_arg, default_arg, *nkwargs, **kwargs)
See documentation for more on defining functions.