Python:查找我正在使用的函数版本

时间:2012-01-25 17:01:00

标签: python introspection import

我对我的导入有点困惑,我想看看我正在使用哪个版本的函数。有没有办法获得实现或类所在的文件名?

2 个答案:

答案 0 :(得分:2)

这适用于大多数功能。它不适用于内置插件,但你无论如何都不会导入它们。

import sys
sys.modules[somefunc.__module__].__file__

答案 1 :(得分:2)

您可以使用标准Python库中的inspect模块

import inspect


inspect.getfile(some_func)
相关问题