Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import csv
import os
from collections import namedtuple
def read_csv(fname, tabname=None, names=None, headers=True):
with open(fname, "r") as fobj:
if not tabname:
full_basename = os.path.basename(fname)
basename, ext = os.path.splitext(full_basename)
tabname = basename.capitalize()
if not names and headers:
names =
Row = namedtuple(tabname, names)
reader = csv.reader(fobj)
for row in reader:
yield Row(*row)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.