Python追加写入文件并换行

将字符串 “1111” 追加写入 a.txt 文件,并换行。

with open("a.txt", mode='a') as f:
    f.write("1111")
    f.write("\n")

注意:mode中"a"是追加模式,"r"是只读模式,默认“w”是重写模式

with open中的参数newline是什么意思?
其中newline是换行控制的参数,参数有:None,'\n','\r','\r\n'。
但是我怎么实现都不好使,有知道了大佬欢迎评论补充,谢谢了

posted @ 2022-06-07 11:37  时光如你般美好  阅读(3725)  评论(0编辑  收藏  举报