reading in lines from a file -FAST!

Mark Day mday at apple.com
Wed Jul 30 20:42:54 EDT 2003


In article <pan.2003.07.30.15.02.20.359182.15518 at presidency.com>,
Rajarshi Guha <rajarshi at presidency.com> wrote:

> Hi
>  I have a file containing 168092 lines (each line a single word) and when
> I use
> 
> for line in f:
>   s = s + line
> 
> it takes for ages to read it all in - so long in fact that it makes the
> program unusable. Is there any way to do something like C's fread in
> Python so that I can just slurp in 1.7MB of data at one go, rather than
> reading line by line?

How about:
    s = f.read()
(assuming f is a file object)

-Mark




More information about the Python-list mailing list