I'm using __init__()
like this in some SQLAlchemy ORM classes that have many parameters (upto 20).
def __init__(self, **kwargs):
for k, v in kwargs.iteritems():
setattr(self, k, v)
Is it "pythonic" to set attributes like this?
Yes. Another way to do this is.
def __init__(self, **kwargs):
self.__dict__.update( kwargs )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With