Difference between binary and text I/O in python on Windows

前端 未结 4 1869
無奈伤痛
無奈伤痛 2021-01-01 15:36

I know that I should open a binary file using \"rb\" instead of \"r\" because Windows behaves differently for binary and non-binary files.

4条回答
  •  失恋的感觉
    2021-01-01 16:20

    For reading files there should be no difference. When writing to text-files Windows will automatically mess up your line-breaks (it will add \r's before the \n's). That's why you should use "wb".

提交回复
热议问题