How to write Unix end of line characters in Windows?

后端 未结 3 1059
执笔经年
执笔经年 2020-11-27 14:42

How can I write to files using Python (on Windows) and use the Unix end of line character?

e.g. When doing:

f = open(\'file.txt\', \'w\')
f.write(\'hello\\n         


        
3条回答
  •  情深已故
    2020-11-27 15:05

    You'll need to use the binary pseudo-mode when opening the file.

    f = open('file.txt', 'wb')
    

提交回复
热议问题