book say this.
db.person.import_from_csv_file(open('test.csv', 'r'))
why do you use a different syntax ?
BTW: you'd need to delete the table first, or you'll append to existent
records in the database the ones in the csv file.
On Wednesday, June 20, 2012 3:55:26 PM UTC+2, joe wrote:
>
> I want to import from a csv file, but I want to use the imported data in
> only one of my database tables, not all of them, which is how I have seen
> the examples online. Here is my code, which does not work:
>
> Model
> -------------------
> db.define_table(
> 'upload',
> Field('name'),
> Field('email'))
>
> db.upload.name.requires = IS_NOT_EMPTY()
> db.upload.email.requires = [IS_EMAIL, IS_NOT_IN_DB(db, 'upload.email')]
>
> Controller
> ----------------------
> def upload():
> db.upload.import_from_csv_file('nameTest.csv')
> records =
> SQLTABLE(db().select(db.upload.ALL),headers='fieldname:capitalize')
> return dict(records=records)
>
>
> View
> ------------------
> {{extend 'layout.html'}}
>
>
> <h2>Current data</h2>
> {{=records}}
>
>
>
>
> I know its basic, but I am just working on getting the feel for things
> before I do a bigger project.
>