What's the most pythonic or elegant way of achieving this?
def __init__(self, connection=None, some=None, thing=None, else=None):
if connection is None:
self.connection = SetConnection()
else:
self.connection = connection
.
.
If I have multiple input args like above for which I would like to call another class to instantiate. Any good way to keep it clean looking without being verbose?
You could use a binary operator:
def __init__(self, connection=None, some=None, thing=None, else=None):
self.connection = connection or SetConnection()
If connection is None (False) it will run SetConnection().
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