python - 每次将字符串写入新行的文件

标签 python newline

每次调用 file.write() 时,我都想在字符串中添加一个换行符。在 Python 中最简单的方法是什么?

最佳答案

使用“\n”:

file.write("My String\n")

the Python manual供引用。

关于python - 每次将字符串写入新行的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2918362/

相关文章:

python - 现实与预测之间的延迟差距

javascript - 在 HTML 和 console.log 中都可见的新行

Powershell换行符不起作用我尝试过 `n "`n"'` n'

python - Python csv writer 是否总是使用 DOS 行尾字符?

python - Django - 为管理错误电子邮件使用不同的电子邮件后端

Python lxml - 获取标签文本的索引

python - 在 Python 中加载格式化二进制文件的最有效方法

linux - 令人费解的 egrep 匹配换行符

c - 从 fgets() 输入中删除尾随换行符

c K&R 计算换行符、制表符和空格