On Thu, Apr 2, 2020 at 6:07 AM Stephen J. Turnbull <
turnbull.stephen...@u.tsukuba.ac.jp> wrote:

> Christopher Barker writes:
>
>  > The funny thing is, in this thread, while I dont really see the need for
>  > adding += to StringIO to make a string builder, I kind of like the idea
> of
>  > adding += to the File protocol -- for all file-like objects.
>
> Yah, but you also get

>
>     outfile.seek(some_random_place)
>     outfile += something
>

Is that not exactly the same as what you can do with .write() now?

> I can see

> folks with severe space constraints "reusing the buffer" with
> something like
>
>     outfile.seek(0)
>     a_loop_of_somesort:
>         outfile += something
>     size = outfile.tell()
>     outfile.seek(0)
>     built_string = outfile.read(size)
>

is this any different than:


    outfile.seek(0)
    a_loop_of_somesort:
        outfile.write(something)
    size = outfile.tell()
    outfile.seek(0)
    built_string = outfile.read(size)

I can't see how the += notation makes that any more likely to happen.

but anyway, it's an argument against the idea of using StringIO as a
"buffer" for strings.

-CHB



-- 
Christopher Barker, PhD

Python Language Consulting
  - Teaching
  - Scientific Software Development
  - Desktop GUI and Web Development
  - wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/FNSJFRTND3YYHS665JWCMMEF2M552AV3/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to