import csv
rows = [row for row in csv.reader(open(file))]
rows[0] = map(lambda h:h.replace(' ','_'), rows[0])


On Tuesday, 26 August 2014 09:07:46 UTC-5, Angelo Mellos wrote:
>
> Hello,
>
> I have a csv that comes from another program that I then import into a 
> web2py database. It has header names with spaces and that seems to prevent 
> it from being imported. I can make a macro in excel to format it before it 
> gets imported, but ideally that wouldn't be necessary mainly because then 
> the other clerks will have to know and remember to do that step.
>
> I thought I could maybe stick something in the def import_csv like this:
>
> def import_csv(table, file):
>     import csv
>     csvData = csv.reader(open(file))
>     isHeader = True
>     for row in csvData:
>         if isHeader:
>             isHeader = False
>             headerRow = row
>             for i in range(len(headerRow)):
>                 # replace spaces w/ underscores in column headers
>                 headerRow[i] = headerRow[i].replace(' ', '_')
>     table.import_from_csv_file(file)
>
> But that doesn't work, and I really don't know if I'm on the right track.
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to