好了,所以,我必須分配在多個文件的file.txt的,這裏的代碼ValueError異常:在關閉的文件I/O操作
a = 0
b = open("sorgente.txt", "r")
c = 5
d = 16 // c
e = 1
f = open("out"+str(e)+".txt", "w")
for line in b:
a += 1
f.writelines(line)
if a == d:
e += 1
a = 0
f.close()
f.close()
所以,如果我運行它,它給了我這個錯誤:
todoController\WordlistSplitter.py", line 9, in <module>
f.writelines(line)
ValueError: I/O operation on closed file
我明白,如果你的循環做一個文件被關閉,所以我試圖把f在for循環,但它不工作的原因不是得到的:
out1.txt
1
2
3
4
out2.txt
5
6
7
8
我只得到文件的最後一行。我應該怎麼做,有什麼辦法可以回想起我之前定義的開放函數?我是一個非常新的Python,所以我很抱歉,如果我問了一些我不能做的事,請耐心等待:D
感謝它的工作:D – Maxpnl