
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. I like the compactness of:
with open(filename, 'w') as outfile: a_loop_of_somesort: outfile += something
And hey, then you'd get your string builder!
Yah, but you also get outfile.seek(some_random_place) outfile += something for free. This seems like what mathematicians call "abuse of notation." While normally the rule is "consenting adults", 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) I'm not a fan. Steve