Name of function within the function?
Darrell
Darrell at p98.f112.n480.z2.fidonet.org
Thu Jul 1 05:48:09 EDT 1999
More information about the Python-list mailing list
Thu Jul 1 05:48:09 EDT 1999
- Previous message (by thread): Name of function within the function?
- Next message (by thread): Name of function within the function?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
From: "Darrell" <news at dorb.com> import sys, string, os def myDirExcept(howFarBack): """ Get the directory of the module running at "howfarBack " in the stack frames This value is compiled into the .pyc file This can be a problem. This name will change depending on where python was run from when the pyc file was created Unix can store a relative path Windows stores an absolute path """ try: raise ZeroDivisionError except ZeroDivisionError: f = sys.exc_info()[2].tb_frame for i in range(howFarBack): f = f.f_back t = f.f_code fname = t.co_filename p = string.split(fname, os.sep) fname = string.join(p[:-1], os.sep) print t.co_name, fname return fname myDirExcept(0) ################################### E:\ace\v2\code\comp>junk2.py myDirExcept E:\ace\v2\code\comp -- --Darrell Dula, Debbie (EXCHANGE:RICH2:2C25) <violet at americasm01.nt.com> wrote in message news:377B8C2F.80F44F9 at americasm01.nt.com... > I've looked and looked, but can't find the answer to this ... I'm > sure it's right in front of me ... > > > I want the current function's name to be output in my error > messages, but can't figure out how a function can get its own name > (without already knowing it). For example, > > def f1(): > print "Error in function", f1.__name__ > > is not really useful for what I need as I might as well print "Error > in function f1". Is there any generic way I can get the current > function's name? > > Thanks, > Debbie
- Previous message (by thread): Name of function within the function?
- Next message (by thread): Name of function within the function?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list