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

前端 未结 4 1877
無奈伤痛
無奈伤痛 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:26

    In Windows, text mode will convert the newline \n to a carriage return followed by a newline \r\n.

    If you read text in binary mode, there are no problems. If you read binary data in text mode, it will likely be corrupted.

提交回复
热议问题