簡體   English   中英

如何使用python在文本文檔中寫另一行

[英]How would I write another line in a text document with python

https://pastebin.com/iuw39F3x

這就是我正在使用的。 在第43行,您可以看到我正在將字符串寫入文本文件。 一旦腳本再次出現,我希望它在另一行上將另一個字符串寫入文本文件。 我該怎么做?

您打開文件,添加文本並添加新行字符。

最后也關閉文件(您不想嘗試打開已經打開的文件:))

x = open("myfile.txt","a")
x.write("the line here" + '\n')
x.close() 

就你而言

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM