You have a problem with b in open . The rt flag (read, text) is the default, so using the context manager, just do the following:
with open('sample.csv') as ifile: read = csv.reader(ifile) for row in read: print (row)
The context manager means that you do not need general error handling (without which you can get stuck in opening a file, especially in the interpreter), because it will automatically close the file when an error occurs or when you exit the context.
The above value is the same as:
with open('sample.csv', 'r') as ifile: ...
or
with open('sample.csv', 'rt') as ifile: ...
Aaron Hall Feb 12 '15 at 21:44 2015-02-12 21:44
source share