I guess there is no way in Python of emulating
>Matlab"s detection of the number of output arguments.
I just got a response from c.l.p. Somebody remembered seeing this at ASPN:
expecting() is the workhorse, equivalent to Matlab's nargout:
"""Return how many values the caller is expecting"""
f = inspect.currentframe()
f = f.f_back.f_back
c = f.f_code
i = f.f_lasti
bytecode = c.co_code
instruction = ord(bytecode[i+3])
if instruction == dis.opmap['UNPACK_SEQUENCE']:
howmany = ord(bytecode[i+4])
elif instruction == dis.opmap['POP_TOP']:
howmany = expecting()
if howmany == 0:
print "return value discarded"
if howmany == 2:
elif howmany == 3:
x = cleverfunc()
x,y = cleverfunc()
x,y,z = cleverfunc()