好了,所以,我必须分配在多个文件的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