
On Mon, Mar 30, 2020 at 10:00 PM Steven D'Aprano <steve@pearwood.info> wrote:
it’s optimized for a different use case than string building,
It is? That's odd. The whole purpose of StringIO is to build strings.
What use-case do you believe it is optimized for?
Let me tell you, since I was there. StringIO was created in order to fit code designed to a file, where all you want to do is capture its output and process it further, in the same process. (Or vice versa for the reading case of course.) IOW its *primary* feature is that it is a duck type for a file, and that is what it's optimized for. Also note that it only applies to use cases where the data does, indeed, fit in the process's memory somewhat easily -- else you should probably use a temporary file. If the filesystem were fast enough and temporary files were easier to use we wouldn't have needed it. -- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-c...>