[英]Printing to text file using Python
我编写了以下代码,并执行了几次:
import statements....
#Scrape some information....
text_file = open("Output.txt", "w")
text_file.write('some text')
for each in array:
#some code to find the value of row...
text_file.write(str(row.encode('ascii', errors='ignore')))
print (row.encode('ascii', errors='ignore'))
text_file.close()
但是,仅将“某些文本”写入文件。 我已经打印了行文本,它会产生正确的输出。 我究竟做错了什么?
以open(“ Output.txt”,“ a”)而不是仅以“ w”形式打开文件。 这将允许您附加其余的文本。
https://docs.python.org/3/tutorial/inputoutput.html#reading-and-writing-files
玩得开心!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.