Effective Python: Introspection
Get the arguments of a function.
import inspect
def f(a, b, c, d):
= inspect.currentframe()
frame = inspect.getargvalues(frame).locals
spec for n in ['frame']:
if n in spec:
spec.pop(n)
= f = g = 999
e
return spec
1,2,3,4)
f(>>> {'a': 1, 'b': 2, 'c': 3, 'd': 4}
posted 2022-07-05 | tags: Effective Python, Python, introspection