I have the following code:
import functools
import random
import inspect
def myfirst(a, b):
return a + b
def mysecond(c, d):
return c - d
def returnAPartial():
myrand = random.randrange(0,2)
if myrand == 1:
return functools.partial(myfirst, 1)
else:
return functools.partial(mysecond, 2)
I load it into python interactive and run:
myfunc = returnAPartial()
I want to check (programmatically) if myfunc is a partial application of the myfirst or mysecond function (not by calculating, the example is a bit contrived) So far I have used inspect.getmembers() but I couldn’t find a suitable attribute to check?
partialobjects have afuncattribute, which is what you want: