Skip to content

Instantly share code, notes, and snippets.

@groovecoder
Created January 29, 2012 23:40
Show Gist options
  • Select an option

  • Save groovecoder/1701382 to your computer and use it in GitHub Desktop.

Select an option

Save groovecoder/1701382 to your computer and use it in GitHub Desktop.
AttributeError: 'module' object has no attribute 'writer'
import csv
import os
STORING_TO_CSV = False
if 'STORE_TO_CSV' in os.environ:
facilities_csv = csv.writer(open('thd_facilities.csv', 'w'))
inspections_csv = csv.writer(open('thd_inspections.csv', 'w'))
STORING_TO_CSV = True
print "Storing to CSV"
def save_facility(facility):
if STORING_TO_CSV:
facilities_csv.writerow(**facility.values())
def save_inspection(inspection):
if STORING_TO_CSV:
inspections_csv.writerow(**inspection.values())
@groovecoder

Copy link
Copy Markdown
Author

note to self: don't import csv from a file named csv.py

@abraham

abraham commented Feb 25, 2013

Copy link
Copy Markdown

Thanks for the comment. I just ran into the exact same issue...

@briancline

Copy link
Copy Markdown

Ditto. Thanks.

@randallm

randallm commented Jul 2, 2014

Copy link
Copy Markdown

Thanks!

@minion96

Copy link
Copy Markdown

Thanks! Just did the same

@shivendrapratap2

Copy link
Copy Markdown

So everybody found csv as a good name for file. LoL !!
Thanks Man.

@akhilpsin

Copy link
Copy Markdown

thanks i did the same

@ajith-reddy-dev

Copy link
Copy Markdown

Thanks.. csv.py is the culprit.. don't use the name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment