I am learning about partials and when to use them. In this page about partials vs lambdas, the accepted answer explains that one of the advantages of partials
over lambdas
, is that partials have attributes useful for introspection. So we can do the following with partials:
import functools
f = functools.partial(int, base=2)
print f.args, f.func, f.keywords
((), int, {'base': 2})
Indeed, we cannot do that with lambdas
:
h = lambda x : int(x,base=2)
print h.args, h.func, h.keywords
AttributeError: 'function' object has no attribute 'args'
But actually, we cannot do that with "normal" Python functions either:
def g(x) :
return int(x,base=2)
print g.args, g.func, g.keywords
AttributeError: 'function' object has no attribute 'args'
Why do partials have more functionalities than normal Python functions? What is the intent of such a design? Is introspection considered useless for normal functions?