[英]append a new line to a file python
I have a file that contains one line 我有一个包含一行的文件
car
I want to append a new line to the file 我想在文件中添加新行
when I used this code: 当我使用此代码时:
f = open("motors.txt","a")
f.write("Bicycle")
I got the following: 我得到以下内容:
carBicycle
how could I append the new word to a new line 我如何将新单词附加到新行中
带换行符 ( \\n
)的前缀Bicycle
,使它写在新行上:
f.write("\nBicycle")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.