On Mon, 16 Aug 99 22:12:49 GMT, philh@vision25.demon.co.uk (Phil Hunt) wrote:
> Is if possible in Python to have a function that prints the name
> of the function that called it. (I'm thinking of using this in
> some debugging code I want to write).
Yes, it's possible, take a look at the traceback module. I use this piece of
code to print the name of function that invokes the 'should' function:
import traceback
def should (condition, message=None):
if (not condition):
methodName = traceback.extract_stack()[-2][2]
fail ("%s: %s" % (methodName, message))
Greetings,
--
Ovidiu Predescu <ovidiu@cup.hp.com>
http://andromeda.cup.hp.com/ (inside HP's firewall only)
http://www.geocities.com/SiliconValley/Monitor/7464/