我有简单的代码:
f = open('out.txt','w')
f.write('line1\n')
f.write('line2')
f.close()
Run Code Online (Sandbox Code Playgroud)
代码在Windows上运行并给出文件大小12 bytes,而linux给出11 bytes
的原因是新行
在Linux中它是\n胜利的\r\n
但在我的代码中,我将新行指定为\n.问题是如何让python像\n往常一样保持新行,而不是检查操作系统.