让我们想象一下,我有一个foo.py声明了函数的模块foofunc:
def foofunc():
# smart things
return
还有两个不同的模块 -bar.py和spam.py,其中存在直接从foo模块执行功能的代码。
# `bar` module. All rights reserved.
from foo import foofunc
def run_foofunc():
return foofunc()
另一个模块中的相同内容:
# `spam` module. All rights reserved.
from foo import foofunc
def run_foofunc():
return foofunc()
我需要知道在不知道可能位置的情况下在哪里执行该功能。就像是:
def foofunc():
print inspect.executedfrom()
会在标准输出中做类似的事情
<pack.bar.run_foofunc>
它在现实世界中有类似的东西吗?