Skip to content

Instantly share code, notes, and snippets.

@jamiesun
Created September 21, 2012 10:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiesun/3760891 to your computer and use it in GitHub Desktop.
Save jamiesun/3760891 to your computer and use it in GitHub Desktop.
namedtuple
EmployeeRecord = namedtuple('EmployeeRecord', 'name, age, title, department, paygrade')
import csv
for emp in map(EmployeeRecord._make, csv.reader(open("employees.csv", "rb"))):
print emp.name, emp.title
import sqlite3
conn = sqlite3.connect('/companydata')
cursor = conn.cursor()
cursor.execute('SELECT name, age, title, department, paygrade FROM employees')
for emp in map(EmployeeRecord._make, cursor.fetchall()):
print emp.name, emp.title
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment