Skip to content

Instantly share code, notes, and snippets.

@schmichael
Created September 15, 2011 00:06
Show Gist options
  • Save schmichael/1218174 to your computer and use it in GitHub Desktop.
Save schmichael/1218174 to your computer and use it in GitHub Desktop.
from collections import namedtuple
def read_shifty_csv(f):
cols = None
for line in f:
line = line.strip()
if line.startswith('#'):
cols = namedtuple('cols', line[1:].split(','))
else:
yield cols(*line.split(','))
f = open('test.csv')
import pprint
pprint.pprint(list(read_shifty_csv(f)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment