-2

We are using Google App Engine with Python for our application. I already wrote code that exports data to CSV, using the csv module. But when I try to read from the CSV:

import csv

users_csv_file = self.request.get("users_csv_file")
csv_reader = csv.reader(users_csv_file)

I get this exception:

AttributeError: 'module' object has no attribute 'reader'

What is the problem and why can't I import csv?

Uri
  • 2,992
  • 8
  • 43
  • 86

2 Answers2

0

Eventually I found the problem. I had a directory "csv" and when I imported csv it imported my local directory, which didn't have an attribute reader. I renamed the directory to "_csv" and this solved the problem.

Uri
  • 2,992
  • 8
  • 43
  • 86
-2

You have to pass in a file object, not a file name.

import csv
with open('eggs.csv', 'rb') as csvfile:
    spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
    for row in spamreader:
        print ', '.join(row)

Spam, Spam, Spam, Spam, Spam, Baked Beans Spam, Lovely Spam, Wonderful Spam