.readline() - VERY SLOW compared to PERL

Christian Tismer tismer at tismer.com
Sat Nov 18 17:20:53 CET 2000


Harald Schneider wrote:
> 
> Thanks or your reply. .readlines() won't fit, since the data is VERY huge.
> So .readline() is a must.
> 
> The link on parmassus is definitive dead .... :-/
> 
> Harald
> 
> > So, why not try using the simpler 'for line in f.readlines()'
> > approach and see what that does to your performance.

Of course you can use readlines.

>From the docs:"""
readlines ([sizehint]) 
Read until EOF using readline() and return a list containing the lines thus
read. If the optional sizehint argument is present, instead of reading up to
EOF, whole lines totalling approximately sizehint bytes (possibly after rounding
up to an internal buffer size) are read. 
"""

In other words, readlines(sizehint) gives you the opportunity
to work through your file in larger chunks of lines, without
reading everything at once.

hope this helps - chris

-- 
Christian Tismer             :^)   <mailto:tismer at tismer.com>
Mission Impossible 5oftware  :     Have a break! Take a ride on Python's
Kaunstr. 26                  :    *Starship* http://starship.python.net
14163 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     where do you want to jump today?   http://www.stackless.com




More information about the Python-list mailing list