functions

Peter Otten __peter__ at web.de
Fri Nov 28 03:46:07 EST 2008


Girish wrote:

> Is ter any way to identify the file name and the path in which the
> function is called.
> 
> for example: if the function definition is in the file c:\script1.py
> and if I call this function in a script: c:\script2.py than in the
> function definition part(script1.py) some how I need to know that its
> called in c:\script2.py.

You can inspect the stack:

import sys
import inspect

def some_func():
    print inspect.getfile(sys._getframe(1))

Peter



More information about the Python-list mailing list