Pythonic way to initialize an object with a lot of parameters and default value

Viewed 3623

I need to create a class wich take a lot of parameters.

class Line:

    def __init__(self, name, nb = None, price_unit = None, total = None, 
                 unit = None, time = None, session = None ):

Every attribute will get the same name and the same value as the parameter passed to __init__().

So, of course i could do :

class MyClass:

    def __init__(self, name, nb = None, price_unit = None, total = None, 
                 unit = None, time = None, session = None ):
        self.name = name
        self.nb = nb
        self.price = price
        self.price_unit = price_unit
        self.total = total
        self.unit = unit
        self.time = time
        self.session = session

But that's a really heavy notation and doesn't seems pythonic to me. Do you know a more pythonic manner to do it ?

3 Answers
Related