
March 31, 2020
8:07 a.m.
Steven D'Aprano writes:
On Mon, Mar 30, 2020 at 10:08:06PM -0700, Guido van Rossum wrote:
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.
But it does that by *building a string*, does it not?
Not all two-pass processes on external streams build strings internally. At least, earlier you insisted that StringIO is not a string.
That's what the getvalue() method is for.
True, but there's no guarantee a given process will ever invoke it. For example, I might read a file encoded as ISO-2022 into a StringIO, then read that StringIO normalizing it to another StringIO as NFD, then encode it to a file as UTF-8. Look Ma, no .getvalue! Steve