Skip to content

Instantly share code, notes, and snippets.

@drewyeaton
Created April 24, 2012 21:39
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 drewyeaton/2484095 to your computer and use it in GitHub Desktop.
Save drewyeaton/2484095 to your computer and use it in GitHub Desktop.
CSV Mapper API
# manufacturer,model,year,price,condition
# BMW,M Coupe,2002,34999.95,good
# BMW,330Ci,2001,13455.36,bad
# Honda,Civic,2007,27340.10,fair
# Toyota,Corolla,2003,14003.21,bad
valid_price = lambda i: i >= 0
class Car(CsvModelBase):
make = StringColumn(col_name='manufacturer')
model = StringColumn()
price = FloatColumn(validate=[valid_price,])
year = IntegerColumn()
cf = open('cars.csv', 'r')
for car in Car.datasource(cf):
print car.make, car.year, car.price
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment