Does Python have any equivalent of nargout in MATLAB? I find nargout a very neat approach if we want to keep the number of return parameters flexible. Is there a way I can find out how many output parameters have been requested? Something like the following pseudo-python-code:
def var_returns_func(a):
"""
a is a 1D numpy array
"""
if nargout==1: return a.sum()
elif nargout==2: return a.sum(),a.std()
So if I call this function as mean = var_returns_func(someNumPyarray)
, it should return a single value. But if I call it as mean,std = var_returns_func(someNumPyarray)
, it should return 2 values.
Is there a Pythonic way of doing this? Or a hacky way?
See Question&Answers more detail:os