使用dir(module)将列出我模块的所有点选项,但是,某些模块要求您显式导入它,然后才能在目录中查看它。
如何无需运行即可查看模块的所有扩展
from modulename import *
即
>>>import sklearn
>>>dir(sklearn)
['__SKLEARN_SETUP__',
'__all__',
...
...
'sys',
'utils',
'warnings']
之后
>>>import sklearn.tree
>>>dir(sklearn)
['__SKLEARN_SETUP__',
'__all__',
...
...
'sys',
'tree', #Now it has been added to the list
'utils',
'warnings']
答案 0 :(得分:0)
原来,检查模块有一个很好的方法!
import inspect
inspect.getmembers(modulename)[1] # [1] gives us the stuff we want
对于sklearn案例:
>>>inspect.getmembers(sklearn)[1]
('__all__',
['calibration',
'cluster',
'covariance',
...
...
'svm',
'tree', # There she is
'discriminant_analysis',
'impute',
'compose',
'clone',
'get_config',
'set_config',
'config_context',
'show_versions'])