for audit - 来自audit.status导入状态 在哪里,"状态"在audit.status中是模块名称和最后一个" status"是班级名称。
我使用的是__import__
,
temp = __import__ ("audit.status"), globals=(), locals=(), fromlist=["status"]
classname = temp.status
并且它运行良好,但是如何使用我在下面的语句中使用上面的方法获取的模块名来获取函数名称:
[obj in getmembers(module_name)如果isfunction(obj [1])]
答案 0 :(得分:0)
如果您要问"如何找到模块对象的所有可调用属性?",
>>> import math
>>> attrs = [getattr(math, name) for name in dir(math)]
>>> callables = [attr for attr in attrs if hasattr(attr, "__call__")]
>>> print callables
[<built-in function acos>, <built-in function acosh>, <built-in function asin>,
...
<built-in function tan>, <built-in function tanh>, <built-in function trunc>]
或者,如果您只想要名称而不是属性本身,
>>> names = [name for name in dir(math) if hasattr(getattr(math, name), "__call__")]
>>> print names
['acos', 'acosh', 'asin', ... 'tan', 'tanh', 'trunc']