I wanna make a init method which can understand these contstrutors.
candy(name="foo", type="bar")
or pass into a whole dict
candy({"name":"foo" , "type":"bar"})
class candy:
def __init__ ?????
How can I make the init method such that accommodate both constructor??
Thanks for help
You can define the init as normal, for example:
class candy(object):
def __init__(self, name, type):
self.name = name
self.type = type
and then pass arguments in both ways:
candy(name='name', type='type')
or
candy(**{ 'name': 'name', 'type': 'type' })
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