A
Aaron \Castironpi\ Brady
Hello,
The 'inspect' module has this method:
inspect.getargvalues(frame)
It takes a frame and returns the parameters used to call it, including
the locals as defined in the frame, as shown.
.... import inspect
.... return inspect.getargvalues( inspect.currentframe() )
....(['a', 'b', 'd'], 'c', 'e', {'a': 0, 'c': ('def', (3, 2)), 'b': 1,
'e': {'h': 'g
hi'}, 'd': 'abc', 'inspect': <module 'inspect' from 'C:\Programs
\Python26\lib\in
spect.pyc'>})
However, if you wanted a decorator that examines the parameters to a
function, you're out of luck. By the time you have a frame, you're
already in the function.
Perhaps it would not be as common as something like 'join' for
example, or even the rest of the functions in 'inspect', but do you
think something similar to 'getargvalues' that accepted a function and
an argument list, and returned a dictionary mapping parameters to
values, could be useful?
The 'inspect' module has this method:
inspect.getargvalues(frame)
It takes a frame and returns the parameters used to call it, including
the locals as defined in the frame, as shown.
.... import inspect
.... return inspect.getargvalues( inspect.currentframe() )
....(['a', 'b', 'd'], 'c', 'e', {'a': 0, 'c': ('def', (3, 2)), 'b': 1,
'e': {'h': 'g
hi'}, 'd': 'abc', 'inspect': <module 'inspect' from 'C:\Programs
\Python26\lib\in
spect.pyc'>})
However, if you wanted a decorator that examines the parameters to a
function, you're out of luck. By the time you have a frame, you're
already in the function.
Perhaps it would not be as common as something like 'join' for
example, or even the rest of the functions in 'inspect', but do you
think something similar to 'getargvalues' that accepted a function and
an argument list, and returned a dictionary mapping parameters to
values, could be useful?