![](/img/trans.png)
[英]How would I tell Python to write to a new line if the previous line is occupied with other text?
[英]How would I write another line in a text document with python
這就是我正在使用的。 在第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.