I need to create a class that requires a lot of parameters.
class Line:
def __init__(self, name, nb = None, price_unit = None, total = None,
unit = None, time = None, session = None ):
Each attribute will receive 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 this is really a heavy notation and does not seem to me pythonic. Do you know a more pythonic manner?
source
share