Effective Python: Introspection
programming
Python
effective python
Get the arguments of a function. Used in aggregate.distr.Aggregate.
import inspect
def f(a, b, c, d):
frame = inspect.currentframe()
spec = inspect.getargvalues(frame).locals
for n in ['frame']:
if n in spec:
spec.pop(n)
# internal variables are ignored
e = f = g = 999
return spec
f(1,2,3,4)
>>> {'a': 1, 'b': 2, 'c': 3, 'd': 4}