Is there a way to find the name of the method currently being executed?
aleax at aleax.it
Thu Sep 26 09:36:16 EDT 2002
Craeg K Strong wrote:
> class a:
> def func1(self):
> print "func1 being called"
> def func2(self):
> print "func2 being called"
> In the code sample above, I would like to replace the "func1"
> and "func2" strings with constants so the same code could
> be copied verbatim into multiple functions and do the right
> Is there a way to do this in Python? For example, maybe you could
> get your hands on the call stack and print out stack.__name__
> or something....
Right, that's exactly what I did in:
except that sys._getframe (gets one frame of the call stack,
not all of the stack at once) is what the recipe uses (as
usual, the version in the printed Cookbook, published by
O'Reilly, has better discussion, &c).
More information about the Python-list