Reading CSV - Beginner

I am trying to read a csv file from my desktop and was not successful. I checked the current working directory and pointed to my desktop so this is not a problem. Below is the module I used and the error output I received. I am using Python 3.2.3

import csv  
reader = csv.reader(open(name.csv, mode = 'r'))  
for row in reader:  
    print (row)  

      

Here is my result

Traceback (last call last):
    File "C: / Users / User Name / Desktop / FileName.py", line 2, in
    reader = csv.reader (open (name.csv, mode = 'r'))
NameError: name "Beta" is undefined

Help? Thank!

+3


source to share


1 answer


Try it...



import csv
with open('name.csv', 'r') as csvfile:
    reader = csv.reader(csvfile, delimiter=',')
    for row in reader:
        print row

      

+5


source







All Articles