如何获取导入我的文件名?

2024-04-19 06:09:47 发布

您现在位置:Python中文网/ 问答频道 /正文

假设有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.pyB.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()函数的东西,该函数获取导入我的模块的名称(假设我是一个模块)?你知道吗


Tags: 模块andthenamepyimportgetby