when you do
for line in open('afile.txt'):
do_something_on_line
you are using a generator that is memory-friendly. readlines() creates a
whole list of lines beforehand, so it uses more memory.
On Saturday, April 4, 2015 at 10:09:50 PM UTC+2, Alex Glaros wrote:
your new example worked,
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,
your new example worked, as did the readlines()
is there any advantage to either method, especially if importing millions
of records? I mean for example, will memory run out if use readlines()?
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
-
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:
problem solved
solution was had to use readlines() not read()
thanks Niphlod
Here's working result
def import_a_tab_file():
tabbed_file =
open(os.path.join(request.folder,'static','city.txt')).readlines()
for line in tabbed_file:
splitted = line.split('\t')
okay, have been approaching the wrong way. Can you please help me write the
correct code? Here's first attempt:
def import_a_tab_file():
rows = open(filename, 'cities1000.txt') ## question: what directory is
source file in?
for row in rows:
db.City.insert(city_name =
why do you need appadmin ? it doesn't import any csv you have lying
around.. code a loop over your nicely tab separated lines that inserts
into your table.
On Thursday, April 2, 2015 at 9:03:07 PM UTC+2, Alex Glaros wrote:
am trying to import geonames.org cites/countries files, which are
I'm not going to give you the complete solution...
a) use https://docs.python.org/2/library/codecs.html to open the file
b) use os.path.join to concatenate pieces of paths to build the file
location
c) assuming
splitted = line.split('\t')
you're going to get a list of values for every row.
hint on this error?
type 'exceptions.IndexError' list index out of range
def import_a_tab_file():
tabbed_file =
open(os.path.join(request.folder,'static','cities1000.txt')).read()
for line in tabbed_file:
splitted = line.split('\t')
db.TempCity.insert(geoNamesID =
ran a display of data
there is only one value: splitted[0] = '9' which causes list index out of
range error
how can I get the rest of the values in the line?
thanks
Alex
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source
am trying to import geonames.org cites/countries files, which are tab
delimited
I guess the linux tr command is a good choice
tr '\t' ',' cities1000.txt comma-delimited-file
Question: is CSV the only format appadmin accepts?
--
Resources:
- http://web2py.com
- http://web2py.com/book
is a tool really needed ?
for line in file:
values = line.split('\t')
.
On Thursday, April 2, 2015 at 12:33:54 AM UTC+2, Alex Glaros wrote:
Niphlod, I don't know how to apply that information to this web2py upload
project.
avoiding Excel, I edited with vi editor (replaced
this looks like something that would be very valuable to me but I don't
know what it is. Can you please explain explicitly?
is it replacing all tabs with a comma?
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
-
nope. if you need to parse a tab separated file, why on earth would you
want to convert it to a csv ?
On Thursday, April 2, 2015 at 6:31:45 PM UTC+2, Alex Glaros wrote:
this looks like something that would be very valuable to me but I don't
know what it is. Can you please explain
they handle foreign files with
https://docs.python.org/2/library/codecs.html as it's supposed to be ^_^
On Wednesday, April 1, 2015 at 11:08:42 PM UTC+2, Alex Glaros wrote:
wait
I closed and opened Excel and question marks are there. Probably not
web2py's fault then.
So updated
wait
I closed and opened Excel and question marks are there. Probably not
web2py's fault then.
So updated question is how do most people take tab delimited table and
convert to CSV so web2py can import?
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
-
Niphold, I don't know how to apply that information to this web2py upload
project.
avoiding Excel, I edited with vi editor (replaced commas with semicolons,
then replaced tabs with commas)
that worked and web2py imported symbols correctly
but now I get this error:
field larger than field
17 matches
Mail list logo