简体   繁体   English

如何使用python在文本文档中写另一行

[英]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.

相关问题 如果前一行被其他文本占用,我如何告诉Python写到新行? - How would I tell Python to write to a new line if the previous line is occupied with other text? 我如何将分数 1 和 2 写入 python 中的文本文件? - how would i write scores 1&2 to a text file in python? 如何在文本文档中的第 n 个单词之后创建一个新行? - How would I create a new line in a text document after the nth word? 我将如何在 java 中编写此 python 代码 - How would i write this python code in java Python:我该如何编写键盘事件? - Python: how would I write a keyevent? 我将如何从 c 到 python 写这个? - How would I write this from c to python? 我有一个文本文档,我想将所有内容复制到特定关键字之后的一行中。 我该怎么做? - I have a text document, and I want to copy everything in a line after a specific keyword. How would I do this? Python-我将如何从 html 文档中获取文本块 - Python-How would i go about getting block of text from an html document 我如何将字符串从另一个文本文件(逐行读取)放入数组中,但只读取每隔一行 - How would i put strings into an array from another text file (reading line by line) but only reading every other line 如何在Python中创建新行? - How would I create a new line in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM