Fast File Input

Terry Reedy tjreedy at udel.edu
Wed Feb 25 12:22:22 EST 2004


"Scott Brady Drummonds" <scott.b.drummonds.nospam at intel.com> wrote in
message news:c1iit0$2jj$1 at news01.intel.com...
> 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.

for line in file('somefile.txt'): ...
will be faster because the file iterator reads a much larger block with
each disk access.

Do you really need strip()?  Clipping \n off the last item after split()
*might* be faster.

Terry J. Reedy







More information about the Python-list mailing list