Reading CSV - Beginner
Question: I have been trying to read a csv file from my desktop and have not been
successful. I checked my current working directory and it is pointed to my
desktop, so that doesn't seem to be the issue. Below is the module I used and
the error output that 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 (most recent 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 not defined

Help? Thanks!


Answer: Try this...

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

