function which knows who has called it.

Darrell news at
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
                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

Phil Hunt <philh at> wrote in message
news:934841569snz at
> 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

More information about the Python-list mailing list