将行写入 Python 中的文件
Writing lines to file in Python
知道写多行之前被问过百万次:
通常推荐的方法似乎是像这样用 \n 连接行:
f = open("fileName", "a")
ptMembers = ['hello', 'world']
trackPoint = '/n'.join(ptMembers)
f.write(trackPoint)
期望在文件中看到:
hello
world
实际上换行文字 \n 是这样进入文件的:
hello\nworld
这是为什么?除了单独写每一行之外,它是否可以被覆盖?
正如 SyntaxVoid 所指出的,问题中有一个拼写错误 - 这是从代码中复制的。这就是全部问题。
知道写多行之前被问过百万次:
通常推荐的方法似乎是像这样用 \n 连接行:
f = open("fileName", "a")
ptMembers = ['hello', 'world']
trackPoint = '/n'.join(ptMembers)
f.write(trackPoint)
期望在文件中看到:
hello
world
实际上换行文字 \n 是这样进入文件的:
hello\nworld
这是为什么?除了单独写每一行之外,它是否可以被覆盖?
正如 SyntaxVoid 所指出的,问题中有一个拼写错误 - 这是从代码中复制的。这就是全部问题。