I want to build up a long string piece by piece without the quadratic
behavior of string concatenation. I'm looking at the {c,}StringIO
modules as a way around this, but I don't see anything in the docs which
talks about how they work. If I do
s = StringIO.StringIO()
while whatever:
s.write (stringFragment)
return s.getvalue()
will I see quadratic behavior? cStringIO claims to be more efficient,
but doesn't say how. Is it algorithmicly better, or just the same
algorithm recoded in C?
The context here is writing a __str__() method for a container class. I
could envision the containiner holding a couple thousand items, with
len(__str__()) being several 10's of kbytes.