Fast File Input

Andrei fake at fake.net
Wed Feb 25 13:29:07 EST 2004


Scott Brady Drummonds wrote on Wed, 25 Feb 2004 08:35:43 -0800:

> Hi, everyone,
> 
> I'm a relative novice to Python and am trying to reduce the processing time
> for a very large text file that I am reading into my Python script.  I'm
> currently reading each line one at a time (readline()), stripping the
> leading and trailing whitespace (strip()) and splitting it's delimited data
> (split()).  For my large input files, this text processing is taking many
> hours.

An easy improvement is using "for line in sometextfile:" instead of
repetitive readline(). Not sure how much time this will save you (depends
on what you're doing after reading), but it can make a difference at
virtually no cost. You might also want to try rstrip() instead of strip()
(not sure if it's faster, but perhaps it is).

-- 
Yours,

Andrei

=====
Real contact info (decode with rot13):
cebwrpg5 at jnanqbb.ay. Fcnz-serr! Cyrnfr qb abg hfr va choyvp cbfgf. V ernq
gur yvfg, fb gurer'f ab arrq gb PP.



More information about the Python-list mailing list