* .pyファイルを再帰的に処理するためのコードを記述しています。再帰がPythonで動作しないようです
class FileProcessor(object):
def convert(self,file_path):
if os.path.isdir(file_path):
""" If the path is a directory,then process it recursively
untill a file is met"""
dir_list=os.listdir(file_path)
print("Now Processing Directory:",file_path)
i=1
for temp_dir in dir_list:
print(i,":",temp_dir)
i=i+1
self.convert(temp_dir)
else:
""" if the path is not a directory"""
""" TODO something meaningful """
if __name__ == '__main__':
tempObj=FileProcessor()
tempObj.convert(sys.argv[1])
私は、引数としてディレクトリ・パスを持つスクリプトを実行し、それが唯一のディレクトリの最初の層を実行し、行:
self.convert(temp_dir)
は決して得る思わなかったコードブロックは、以下の通りですと呼ばれる。私はPython 3.5を使用しています。
に
を変更する必要があります。 ['os.walk'](https://docs.python.org/3/library/os.html#os.walk) –