作者yycsan (老头一个)
看板Python
标题[问题]第二个For loop 只被执行一次
时间Sat Nov 2 20:14:53 2013
你好,请问不知道为什麽,我底下的for loop只会跑一次:
import os
output_file1=open('result_exception.txt','w',encoding="utf-8")
all_error_output=open('all_error_output.txt',encoding="utf-8")
exceptionlist=open('exceptionlist.txt',encoding="utf-8")
for each_line1 in all_error_output:
print(each_line1,end="",file=output_file1)
for each_line2 in exceptionlist:
print(each_line2,end="",file=output_file1)
output_file1.close()
exceptionlist.close()
all_error_output.close()
底下是all_error_output.txt内容
1;aaaa;1111
2;bbbb;2222
3;cccc;3333
底下是all_error_output.txt内容
1;aaaa;111
2;bbbb;222
底下是结果
1;aaaa;1111
1;aaaa;111
2;bbbb;222
2;bbbb;2222
3;cccc;3333
谢谢
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 182.234.234.100
1F:→ jlhg:你想跑什麽结果? 11/02 20:52
2F:推 grtfor:因为档案就像tape一样,不重新开关档,它会读上一次的位置 11/02 20:59
3F:→ grtfor:或者你可以用seek(0) 11/02 21:02
4F:→ hyderai:因为第二层的for跑完一轮,位置就是指向档案最後啦 11/02 21:06
5F:推 jlhc:看到一楼想说 我怎麽自己推文了 11/03 01:29
6F:→ yycsan:谢谢大家....seek(0)解决了我低问题...谢谢.. 11/07 00:16