Skip to content

Instantly share code, notes, and snippets.

@lxneng
Created August 30, 2012 04:35
Show Gist options
  • Save lxneng/3522361 to your computer and use it in GitHub Desktop.
Save lxneng/3522361 to your computer and use it in GitHub Desktop.
>>> import csv
>>> reader = csv.reader(open('ttt.csv'))
>>> keys = reader.next()
>>> data = [dict(zip(keys, property)) for property in reader]
>>>
@wujiang
Copy link

wujiang commented Jun 11, 2013

That will load the whole csv into memory which will be problematic when the file is large.

>>> with open("ttt.csv") as f:
>>>     reader = csv.DictReader(f)
>>>     for row in reader:
>>>         ...

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