Stringbuffer
Andrew Dalke
dalke at acm.org
Sun Feb 4 00:50:30 EST 2001
Joshua Marshall:
> buf = []
> while stream.more():
> buf = buf + stream.read()
> 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():
buf.write(stream.read())
s = buf.getvalue()
Or you can use an array
import array
buf = array.array("c", "")
while stream.more():
buf.fromstring(stream.read())
s = buf.tostring()
Must admit that I would like the method names to be more
similar between these two.
Andrew
dalke at acm.org
More information about the Python-list
mailing list