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