12
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?

Community
  • 1
  • 1
evtoh
  • 444
  • 3
  • 10
  • 21
  • 1
    Quite a few questions on this, e.g. [this one](http://stackoverflow.com/questions/15746954/what-is-the-difference-between-rb-and-rb-modes-in-file-objects) – lrnzcig Jun 09 '16 at 15:01

3 Answers3

19

It means: Read the file in Binary mode.

For a complete list of options view this.

Amin Alaee
  • 1,895
  • 17
  • 26
4

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.

fedorqui
  • 275,237
  • 103
  • 548
  • 598
2

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

kylieCatt
  • 10,672
  • 5
  • 43
  • 51