让我们假设有模块A,B,C:
A.py
import C
# do stuff
B.py
import C
# do stuff
C.py
print( "I am the C module and I am being imported by " + get_importer_name() )
然后,当运行A.py
或B.py
时,输出将为:
I am the C module and I am being imported by A
I am the C module and I am being imported by B
是否存在类似get_importer_name()
函数的东西,它获取导入我的模块的名称(假设我是模块)?