Function calls and reflection
pyth at devel.trillke.net
Sun Jan 5 23:19:52 CET 2003
> Can a function tell which function / method called it?
you can get to the name of the caller's function with
>>> def f():
>>> def g():
But ASFAIK there is no direct way to get to the function
*object*. With the following snippet you might get
to a calling function if it is defined at the module level
(e.g. it doesn't get to instance methods).
frame = inspect.currentframe(1)
I am not sure if the frame object provides enough
information to unambigously get to the object
currently executing in it.
"Why are people killing each other when there is so much fun stuff
to be had through friendly cooperation?" (Bengt Richter on c.l.py)
More information about the Python-list