怎么获取Python3模块路径列表的疑惑,获取python3模块路径,相当于nodejs的mo


相当于nodejs的

module.filenamemodule.children

看 module 自身路径用 __file__:

https://docs.python.org/3/reference/import.html?highlight=__file__#import-related-module-attributes

看 module 引用了哪些别的 module 则需要写代码了:

https://docs.python.org/3/library/modulefinder.html

例子摘抄如下:

from modulefinder import ModuleFinderfinder = ModuleFinder()finder.run_script('bacon.py')print('Loaded modules:')for name, mod in finder.modules.items():    print('%s: ' % name, end='')    print(','.join(list(mod.globalnames.keys())[:3]))print('-'*50)print('Modules not imported:')print('\n'.join(finder.badmodules.keys()))

还可以参考这个:http://furius.ca/snakefood/

编橙之家文章,

评论关闭