【发布时间】:2014-05-14 02:42:13
【问题描述】:
我正在尝试为每个模块及其子模块查找所有缺少的导入语句和错误。
是否有专门的工具来处理我正在尝试做的事情?
我写的代码,但看起来真的很糟糕,也许这样的东西已经存在了?:
import os
def find_missing_imports(walk):
for items in walk:
d = items[0]
f_list = items[1]
for f in f_list:
module = f[:-3]
# posix_path
module_path = d.lstrip('.').replace('/','.').lstrip('.')
try:
__import__(module_path, fromlist=[module])
except IndentationError, e:
#print(f,e)
pass
except NameError, e:
print(d,f,e)
pass
except Exception, e:
print(f,e)
pass
walk = [[root,files] for root,dirs,files in os.walk('.') for fn in files if fn.endswith('.py')]
find_missing_imports(walk)
输出:
.[snip]
('./Sky_Group_Inventory_Scanner-wxpython/display_image/Dialogs', 'ImageSelectionFrame.py', NameError("name 'wx' is not defined",))
('./Sky_Group_Inventory_Scanner-wxpython/display_image/Dialogs', 'ItemSpecificsDialog.py', NameError("name 'wx' is not defined",))
('./Sky_Group_Inventory_Scanner-wxpython/display_image/Dialogs', 'ReturnCorrectWatchTitle.py', NameError("name 'wx' is not defined",))
.[snip]
我在重构之前的项目是一团糟但有点用处,现在它在重构之后就坏了。
根据我在 codereview 上的最初帖子中的建议阅读“实用程序员”后:
我一直在挖源代码:
/usr/local/lib/python2.7/dist-packages/rope
ROPE 的文档似乎有点少。我也一直在使用 Ninja-IDE,但一直没有找到解决我面临的问题的方法。
总的来说,我认为我错过了重构的全部内容。
当前父目录布局可见here.
与 before. 相比
任何关于填写缺失术语的帮助,或者关于我什至要求的任何帮助都会很棒。
解决方案:
pylint -E /path/to/module
【问题讨论】:
标签: python refactoring automated-tests