slow joinings of strings

Carsten Gaebler cg at schlund.de
Tue Jan 30 07:39:16 EST 2001


Karol Bryd wrote:

> I want to read a file (0.6MB, 10000 lines) into memory, and want to do it as
> fast as possible, this code does it, but is terribly slow
> 
> fp = open(file, 'r')
> s = ''
> while 1:
>         line = fp.readline()
>         if line == '': break
>         s = s + line
> 
> (executing time 25 sec)

This should be faster:

s = open(file, 'r').read()


cg.



More information about the Python-list mailing list