what does 'rb' mean in csv files?

28,346

Solution 1

It means: Read the file in Binary mode.

For a complete list of options view this.

Solution 2

From open() in the Built-in functions documentation:

open(name[, mode[, buffering]])

The most commonly-used values of mode are 'r' for reading, (...) Thus, when opening a binary file, you should append 'b' to the mode value to open the file in binary mode, which will improve portability.

So this opens the file to read in a binary mode.

Solution 3

The second argument o open() is the mode the file will be opened in. 'rb' is for Read Binary mode. Read more about it here

Share:
28,346

Related videos on Youtube

evtoh
Author by

evtoh

I write code for astrophysics. Mostly matplotlib.

Updated on June 10, 2020

Comments

  • evtoh
    evtoh almost 4 years
    import csv
    with open('test.csv','rb') as file:
        rows = csv.reader(file, 
                          delimiter = ',', 
                          quotechar = '"')
        data = [data for data in rows]
    

    This was in Python: reading in a csv file and saving columns as variables. I couldn't comment, but I'm really confused. What does 'rb' mean?

    • lrnzcig
      lrnzcig
      Quite a few questions on this, e.g. this one