tabbed_file is holding the entire content!
if you want to use "for line in file" syntax, don't read() beforehand all
the contents...
filename = os.path.join(....)
thefile = open(filename)
for line in thefile:
splitted = line.split('\t')
......
On Friday, April 3, 2015 at 7:08:05 PM UTC+2, Alex Glaros wrote:
>
> need help just for this last part
>
> below works but the whole file gets included instead of the one row. How
> do I specify only one row at a time?
>
> def import_a_tab_file():
> tabbed_file =
> open(os.path.join(request.folder,'static','city.txt')).read()
> for line in tabbed_file:
> splitted = tabbed_file.split('\t') ## help me with this line.
> If use "splitted = line.split('\t')" then only '9' (the total number of
> lines) becomes the splitted value . No data goes into the array
> db.TempCity.insert(geoNamesID = splitted[0], cityName =
> splitted[1], asciiCityName = splitted[2], alternativeNames = splitted[3],
> latitude = splitted[4], longitude = splitted[5], featureClass =
> splitted[6], featureCode = splitted[7], countryCode = splitted[8],
> altCountryCode = splitted[9], admin1Code = splitted[10], admin2Code =
> splitted[11], admin3Code = splitted[12], admin4Code = splitted[13],
> population = splitted[14], elevation = splitted[15], dem = splitted[16],
> timeZone = splitted[17], geoNamesModDate = splitted[18])
> return locals()
>
>
>
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.