Effective Python: Introspection
Get the arguments of a function.
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)
e = f = g = 999
return spec
f(1,2,3,4)
>>> {'a': 1, 'b': 2, 'c': 3, 'd': 4}posted 2022-07-05 | tags: Effective Python, Python, introspection