Difference between a text file in r and rb mode
what’s the Difference between r and rb in fopen
0. EOL (end-of-line)
The difference is mainly in the treatment of EOL. For different operating systems,
Unix: \n
Mac: \r
Windows: \r\n
For the Python language, the query is performed using the following statement:
>> import os
>> os.linesep
'\r\n'
1. Different operating systems
For Windows systems, having b
(rb
, wb
, r+b
) means to open files in binary form. Python on Windows handles text files differently than binary files,
2. Python 2 vs Python 3
For Python 3 environments:
r
: Python returns STR
rb
: binary mode, read()
returns 0 bytes
1