"Zooko O'Whielacronx" <[email protected]> writes:
> Every couple of years I run into a problem where some Python code that
> worked well at small scales starts burning up my CPU at larger scales,
> and the underlying issue turns out to be the idiom of accumulating
> data by string concatenation.
I usually use StringIO or cStringIO for that (python 2.x syntax):
buf = cStringIO()
buf.write("first thing")
buf.write("second thing")
result = buf.getvalue()
Sometimes I like to use a generator instead:
def stuff():
yield "first thing"
yield "second thing"
result = ''.join(stuff())
--
http://mail.python.org/mailman/listinfo/python-list