functions

Girish girish.cfc at gmail.com
Fri Nov 28 04:48:39 EST 2008


On Nov 28, 1:46 pm, Peter Otten <__pete... at web.de> wrote:
> 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

Thanks a lot Peter.



More information about the Python-list mailing list