标签:
问题代码如下
links = open("new") out = open("out.txt","w+") for link in links: out.write(link+"\n")
问题原因:
当没有使用flush()或close()时,要写入的内容依然在缓冲区中,没有写入文件,如果中途终止,文件里就会没有内容。
解决方法:
links = open("new") out = open("out.txt","w+") for link in links: out.write(link+"\n") out.flush()
标签:
原文地址:http://blog.csdn.net/iluckyning/article/details/45841779