jmarshal at mathworks.com
Sun Feb 4 04:37:35 CET 2001
chris at onca.catsden.net wrote:
> On 4 Feb 2001, Joshua Marshall wrote:
>> I'm plucking characters off a stream and concatenating them.
>> Currently, I'm doing something like:
>> 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?
> You could try buf.append(stream.read())
> And... I dont know what you're trying to achive with string.join(buf,'').
> Are you just adding a space?? :)
I'm using string.join to convert a list of strings into a single string.
My use of a list is for efficiency. Intuitively, I'm trying to do:
ret = ''
ret = ret + stream.read()
but this is too slow. Appending to a list is better, but I'm looking
for more speed.
More information about the Python-list