I have a function like this:
def func(foo, bar, nin=None, nout=None):
if not nin:
nin = bar
if not nout:
nout = bar
return foo * nin / nout
It takes in two optional parameters and I need to map them into another compulsory parameter if they are not passed in. But is this the pythonic way to do it? Are there other ways to get the check and set the nin and nout?
if nin is not None:instead ofif not nin:to avoid issues with false-y objects other thanNone.if nin is None: ...etc.nin, nout = kwargs.get("nin", bar),kwargs.get("nout", foo)