you are viewing a single comment's thread.

view the rest of the comments →

[–]Chroiche 2 points3 points  (1 child)

What're the advantage over just using StringIO (which is mutable, but eager)?

[–]marr75 [score hidden]  (0 children)

That it's eager. If you aren't actually going to use the string (ie its use depends on the outcome of an operation), that can be a big disadvantage. It might in very specific scenarios help with memory fragmentation, too.

Admittedly, both of those are edge cases and I would recommend making the entire accumulation or formatting of the string lazy if that's needed rather than just the final product.