2013-02-13 69 views
1

我正在使用pylint來檢查錯誤。我的Python代碼在一個目錄中,該目錄包含許多其他的子文件夾和文件。我遞歸檢查所有文件夾文件以.py結尾。它工作正常。Pylint沒有按預期工作

我的問題是,當我在主目錄中運行腳本時,只有第一個python文件獲取報告正確。第二和第四不工作。 pylint說

************* Module test.py 
    F: 1: No module named test.py 
    *************** 
Global evaluation 
----------------- 
Your code has been rated at 0.00/10 (previous run: 0.00/10) 

每當我在主目錄中運行我的腳本只有第一個文件報告是適當的。 pylint沒有檢查任何其他文件。 (我在子目錄中有近50個python文件)。

以下是我的代碼: - [版本:-python 2.7.2+]

""" 
Automated error handling using pylint 
1. pylint --generate-rcfile > pylintrc 

""" 

import sys 
import os 

if __name__ == '__main__' : 
    if len(sys.argv) > 1: 
     os.system(">output.txt") 
     for r, d, f in os.walk(sys.argv[1]): 
      for files in f: 
       if files.endswith(".py"): 
        os.system("pylint %s >> output.txt" % files) 
    else: 
     os.system(">output.txt") 
     for r, d, f in os.walk('.'): 
      for files in f: 
       if files.endswith(".py"): 
        os.system("pylint %s >> output.txt" % files) 

如何正確獲取所有(幾乎50個文件)的文件報告,之後第一個文件報告了存在的。這是做到這一點的正確方法嗎? 。提前致謝。

+1

你用什麼命令啓動pylint? – 2013-02-13 04:16:17

+0

am直接運行os.system運行pylint – 2013-02-13 04:26:20

+0

如果我的pylint理解錯誤,請幫我改正我的問題 – 2013-02-13 04:30:25

回答

1

你需要傳遞的完整路徑pylint的命令行上,即

for filename in f: 
    if filename.endswith(".py"):      
     os.system("pylint %s >> output.txt" % os.path.join(r, filename)) 

除非你使用有意義的變量名:-)

你不會得到這個劇本非常好pylint的成績
+0

bah ...沒有看到評論中給出的迴應... – 2013-02-13 09:14:38