foo.py:
import bar
bar.py:
import traceback
try:
filename,line_number,function_name,text = traceback.extract_stack()[-2]
print(filename,line_number,function_name,text)
except IndexError:
pass
Running foo.py yields something like
('/home/unutbu/pybin/foo.py', 4, '', 'import bar')