[英]How would I write another line in a text document with python
https://pastebin.com/iuw39F3x https://pastebin.com/iuw39F3x
This is what I'm working with. 这就是我正在使用的。 On line 43 you can see I'm writing a string to a text file.
在第43行,您可以看到我正在将字符串写入文本文件。 Once the script looks again I want it to write another string to the text file on another line.
一旦脚本再次出现,我希望它在另一行上将另一个字符串写入文本文件。 How would I do this?
我该怎么做?
You open the file, add the text and add the new line char... 您打开文件,添加文本并添加新行字符。
Finally close the file too (you don't want to try to open a file that is already open :) ) 最后也关闭文件(您不想尝试打开已经打开的文件:))
x = open("myfile.txt","a")
x.write("the line here" + '\n')
x.close()
In your case 就你而言
file = open("text.txt","a")
file.write(save + '\n') #here add the new line
file.close()
time.sleep(25)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.