我希望Python不斷掃描文件夾,並在文件夾中創建新文件以啓動代碼的其餘部分。雖然循環索引錯誤
但是我堅持在這裏:
import os
os.chdir("path")
a = os.listdir("path")
initial = len(a)
while True:
b = os.listdir("path")
final = len(b)
if final > initial:
c = list(set(b) - set(a))
a.append(c[0])
C [0]附加到列出然而代碼,然後用此錯誤崩潰
a.append(c[0]) IndexError: list index out of range
'print()'c = list(set(b) - 設置(a))'。 –