查看python源代码所依赖的模块,python源代码模块,查看python源代码所
查看python源代码所依赖的模块,python源代码模块,查看python源代码所
查看python源代码所依赖的模块用法:分析一个脚本的依赖:analysis_dependency.pyscript1.py
递归分析依赖:analysis_dependency.pyscript1.py-r
1.[代码][Python]代码
#!/usr/bin/env python# encoding: utf-8import astimport importlibimport inspectclass Analysis(ast.NodeTransformer): def __init__(self, paths, recursion): self.modules = list() self.paths = list(paths) self.recursion = recursion def add_module(self, module): if module and module not in self.modules: self.modules.append(module) if self.recursion: try: path = inspect.getsourcefile(importlib.import_module(module)) if path: self.paths.append(path) except: pass def visit_Import(self, node): for i in node.names: self.add_module(i.name) def visit_ImportFrom(self, node): self.add_module(node.module) def analysis(self): for p in self.paths: try: with open(p, "rt") as fp: self.visit(ast.parse(fp.read(), p)) except: pass return tuple(self.modules)if __name__ == "__main__": """ www.iplaypy.com """ import argparse parser = argparse.ArgumentParser() parser.add_argument("paths", nargs="+") parser.add_argument("-r", "--recursion", action="store_true", default=False) args = parser.parse_args() analysisor = Analysis(args.paths, args.recursion) for m in analysisor.analysis(): print m
编橙之家文章,
相关内容
- python3 bs4 抓取豆瓣MM图片,,python3 bs4
- python编写 ElasticSearch 数据导入导出功能,,python编写
- python来查看Linux系统内存使用情况,pythonlinux,经常系统
- 无序的python字典中取文件倒数第几行,python第几行,无序
- 将3个.py文件合并成一个文件中的3列 笨办法,.py3列
- python 的map和reduce函数把str转为float类型,reducefloat,<
- 闲来无事整一下贪心算法 用python实现的,闲来无事
- python程序记录QQ空间条说说的访问详情,python详情,pyt
- 用python完成计算一个图形中三角形数目,python三角形
- python 狂人TD1.5 krtd1.5积分代码破解教程,td1.5krtd1.5,pyt
评论关闭