I have a python class I want to instantiate and the __init__ definition has a lot of parameters (10+). Is there a clean way to instantiate a class who’s __init__ takes a lot of params?
For example:
class A(object):
def __init__(self, param1, param2, param3,...param13):
// create an instance of A
my_a = new A(param1="foo", param2="bar", param3="hello"....)
Is there a cleaner way to do this? like passing in a dictionary or something? Or better, is there an expected convention?
Yes, you can use a
dictto collect the parameters:See the unpacking argument lists section of the Python tutorial.
Also,
//isn’t a comment in Python, it’s floor division.#is a comment. For multi-line comments,'''You can use triple single quotes'''or"""triple double quotes""".