Andrew Dalke dalke at
Sun Feb 4 00:50:30 EST 2001

Joshua Marshall:
>   buf = []
>   while stream.more():
>      buf = buf +
>   string.join(buf, '')
>Is there a faster way?  I'm thinking of writing a Stringbuffer
>class in C.  Or does a quick, reliable one already exist?

Might want to look at cStringIO

import cStringIO
buf = cStringIO.StringIO()
while stream.more():
s = buf.getvalue()

Or you can use an array

import array
buf = array.array("c", "")
while stream.more():
s = buf.tostring()

Must admit that I would like the method names to be more
similar between these two.

                    dalke at

More information about the Python-list mailing list