functions

G

Girish

Hello,

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.

Thanks,
Giri
 
P

Peter Otten

Girish said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top