>>> from types import FunctionType
>>> functions = [x for x in globals().values() if isinstance( x, FunctionType)]
演示:
from types import FunctionType
def func():pass
print [x for x in globals().values() if isinstance(x, FunctionType)]
#[<function func at 0xb74d795c>]
#to return just name
print [x for x in globals().keys() if isinstance(globals()[x], FunctionType)]
#['func']
您可以使用inspect模块:
印刷品:
可以使用
globals()
获取文件全局范围中定义的所有内容,使用inspect
筛选所关心的对象。你知道吗使用
globals()
和types.FunctionType
演示:
相关问题 更多 >
编程相关推荐