a bug with csv module in python -


import csv open('database.csv') csvfile:     reader = csv.dictreader(csvfile)     row in reader:         print(row['name']) 

guys, have csv file first row index, , in linux code read row['name'] , print names form colum name, when run in windows, says:

c:\users\desktop>python py.py traceback (most recent call last):   file "py.py", line 5, in <module>     print(row['name']) keyerror: 'name' 

why?

if using python 2- versions, need open csv rb, i.e.:

with open('database.csv', 'rb') csvfile:.... 

for reference, checkout https://docs.python.org/2/library/csv.html includes part in reader doc this.


Comments