您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

查找在模块中明确定义的函数(python)

查找在模块中明确定义的函数(python)

您是否正在寻找这样的东西?

import sys, inspect

def is_mod_function(mod, func):
    return inspect.isfunction(func) and inspect.getmodule(func) == mod

def list_functions(mod):
    return [func.__name__ for func in mod.__dict__.itervalues() 
            if is_mod_function(mod, func)]


print 'functions in current module:\n', list_functions(sys.modules[__name__])
print 'functions in inspect module:\n', list_functions(inspect)

编辑:将变量名从“ meth”更改为“ func”以避免混淆(我们在这里处理函数,而不是方法)。

python 2022/1/1 18:26:02 有166人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶