The data isn't formatted quite right. It's looking like I'll have to format
the file a little.
As a test, I tried adding the column names to the top of the .csv file and
import_from_csv_file works. I'm going to make a function to add the column
names to the first line of the file.
Thanks for your help!
On Thursday, April 4, 2013 2:05:54 PM UTC-4, Massimo Di Pierro wrote:
>
> Ok you can do:
>
> colnames = ['field1','field2',etc.]
> for lines in import_data:
> items = lines.split(',')
> db[csv_data].insert(**dict((colnames[i],v) for i,v in
> enumerate(items)))
>
> It may still fail of the data is not in the right format but you can find
> out why.
>
> On Wednesday, 3 April 2013 16:40:01 UTC-5, David S wrote:
>>
>> I'm very new to web2py and python in general but have a bit of knowledge
>> when it comes to C/C++.
>>
>> I've got a db setup which needs to pull data from a row in a .csv file
>> and put each column in the .csv into the corresponding column in the db.
>> Rather than doing this explicitly (there's ~40 columns), I'd like to have
>> each iteration of the for loop correspond to one of the columns. Here's
>> what I've got so far:
>>
>> for lines in import_data:
>> info = lines.split(',')
>> field_name = 'field1'
>> db[csv_data].insert(**{field_name:info})
>>
>> The above puts all the data in 'field1' and not into separate columns,
>> close but not quite. I'm thinking some sort of select from the db might
>> work. Any ideas or links which might help?
>>
>> Thanks,
>> David
>>
>
--
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.