[英]List all third party packages and theirselves functions used in a Python file
[英]List of all functions used in python program as string
我们怎样才能找到python程序中的所有函数? 例如。
输入
def func1:
#doing something
def func2:
#doing something
def func3:
#doing something
产量
{'func1' , 'func2' , 'func3'}
如果您想要全局范围内的所有函数,可以将globals()与inspect.isfunction()一起使用 :
>>> def foo():
... pass
...
>>> def bar():
... pass
...
>>> import inspect
>>> [member.__name__ for member in globals().values() \
... if inspect.isfunction(member)]
['bar', 'foo']
猜猜你只想要当前环境中的方法:
import inspect
d = locals()
funcs = [f for f in d if inspect.isfunction(d[f])]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.