
On Apr 1, 2020, at 14:47, Paul Sokolovsky <pmiscml@gmail.com> wrote:
At the moment, the message is relatively clear - "build a list and join it" (it's very rare that anyone suggests StringIO currently).
I don't know how much you mix with other Pythonistas, but word "clear" is an exaggeration. From those who don't like it, the usual word is "ugly", though I've seen more vivid epithets, like "repulsive": https://mail.python.org/pipermail/python-list/2006-January/403480.html
More cool-headed guys like me just call it "complete wastage of memory"
Then aren’t you going to be disappointed when you’re told you can now use StringIO instead in 3.10, and you start using it everywhere as soon as you can drop 3.9 support, and then you find that in many Python implementations, including CPython, it takes a little more memory than building a list and joining it, not less? The fact that it could theoretically take less memory, and might even do so on some other implementation you aren’t using, is probably not going to be much consolation. Or maybe it is, and you switch to one of those other implementations, because that’s the final straw for CPython for you—and then you discover that, unlike CPython, their StringIO does save memory over str.join, but also unlike CPython it’s also a lot slower than str.join, mainly because its StringIO is encoding every string to UTF-8 when you write and then decoding back at the end. At which point you’re probably ready to give up on Python altogether.