function which knows who has called it.
Darrell
news at dorb.com
Mon Aug 16 20:52:54 EDT 1999
You can get the callers name from this also.
But that's up to you.
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.
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)
return fname
--
--Darrell
Phil Hunt <philh at vision25.demon.co.uk> wrote in message
news:934841569snz at vision25.demon.co.uk...
>
> 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).
>
> --
> Phil Hunt....philh at vision25.demon.co.uk
>
More information about the Python-list
mailing list