【发布时间】:2018-03-05 00:28:54
【问题描述】:
我需要在 Python 中使用几个函数(任一变体)来查找和打印存储或调用它们的文件的名称。例如,考虑以下函数存储在该地址:/my/py/func.py:
def this_file():
# print the address of this file
print('this function is stored at %s' % this_file_address)
和
def that_file():
# print the address of the file that is calling this function
print('this function is called form a file at %s' % that_file_address)
我有一段代码存储在/my/py/calls.py:
from func import *
this_file()
that_file()
现在,我希望通过上述函数打印以下内容:
/my/py/func.py
/my/py/calls.py
如何编写这些函数?
编辑#1
从 Jupyter 笔记本调用 that_file() 似乎应该以不同的方式处理。
【问题讨论】: