0
この関数はファイルパスを返しませんが、リストの追加を使用するとうまくいきます。 このコードを実行するとエラーが発生します。再帰からジェネレータを取得する方法
トレースバック(最後の最新の呼び出し): ファイル "C:/Users/admin/PycharmProjects/testProj/testFile.py"、行28、 で 印刷myFiles.next()を呼び出すとStopIteration
import os
basePath1 = 'D:/my_backup/'
def testFunction(basePath):
for each in os.listdir(basePath):
newBase = basePath
if os.path.isfile(newBase + each):
yield newBase + each
else:
newBase += each + '/'
testFunction(newBase)
myFiles = testFunction(basePath1)
print myFiles.next()
print myFiles.next()
print myFiles.next()
list.appendの使用方法を表示できますか? – TinyTheBrontosaurus
また、そのフォルダには何がありますか? – TinyTheBrontosaurus
インポートOS basePath1 = 'D:/ my_backup /' ます。myList =リスト() DEF testFunction(basePathを):os.listdirにおける各々について (basePathを): newBase = basePathを os.path.isfile IF( newBase +各): #降伏newBase +各 myList.append(newBase +各)他 : newBase + =各+ '/' testFunction(newBase) testFunction(basePath1) 印刷はmyList –