PEP 214 - Why not print >> string?

Steven Majewski sdm7g at Virginia.EDU
Fri Jan 11 11:34:13 EST 2002


On Fri, 11 Jan 2002, Aaron Swartz wrote:

> On 2002-01-11 9:05 AM, in article a1muv5$ljn$1 at panix3.panix.com, "Aahz
> Maruch" <aahz at panix.com> wrote:
>
> > Why does using a [c]StringIO object feel kludgy?  After all, your
> > proposal already requires x='' and using a "normal" file requires an
> > open(), so what's wrong with x=StringIO()?
>
> Well, at the time I wrote that I did not know about StringIO.getvalue(), so
> that removes some concerns. However it still requires the extra import:
>
> from cStringIO import StringIO
>
> I guess it isn't so bad.

Is there any particular reason that [c]StringIO doesn't just return
it's string value in it's __str__ method, so then you could just do:

buffer = StringIO
print >>buffer, "Testing:"
print >>buffer, 1
print >>buffer, 2
print >>buffer, 3
print buffer

?
Which seems more intuitive and natural. (IMHO)

-- Steve Majewski






More information about the Python-list mailing list