Skip to content

Instantly share code, notes, and snippets.

@pfigue
Created December 13, 2013 20:27
Show Gist options
  • Select an option

  • Save pfigue/7950818 to your computer and use it in GitHub Desktop.

Select an option

Save pfigue/7950818 to your computer and use it in GitHub Desktop.
Generator to read a CSV file.
import csv
def rows_from_a_csv_file(filename, skip_first_line=False, dialect='excel', **fmtparams):
with open(filename, 'r') as csv_file:
reader = csv.reader(csv_file, dialect, **fmtparams)
if skip_first_line:
next(reader, None)
for row in reader:
yield row
## Example:
import sys
if __name__ == '__main__':
csv_file_path = sys.argv[1]
for row in rows_from_a_csv_file(csv_file_path, skip_first_line=True):
print row[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment