[Python-bugs-list] StringIO does not write integers (PR#147)

Dave Gudeman dgudeman@azstarnet.com
Sat, 04 Dec 1999 18:15:10 -0700


Tim Peters wrote:

> > Full_Name: Dave Gudeman
> > Version: 1.52
> > OS: windows 95
> > Submission from: dialup19ip095.tus.azstarnet.com (169.197.39.95)
> >
> >
> > The following program demonstrates an inconsistency in StringIO:
> >
> >   from StringIO import *
> >   out = StringIO()
> >   out.write(3)
> >
> > This causes an error message, which is inconsistent with
> > sys.stdout.write(3), which writes out a "3".
>
> Not unless you've rebound sys.stdout to something other than its default!
>
> >>> import sys
> >>> sys.stdout.write(3)
> Traceback (innermost last):
>   File "<stdin>", line 1, in ?
> TypeError: read-only buffer, int
> >>>
>
> Python has very few implicit type conversions, and it would make no sense
> for a .write() method to accept an integer -- it requires a character buffer
> (most commonly a string).  The error msg produced here is trying to say
> that, although it could sure stand some humanization.
>
> Perhaps you're thinking of the "print" stmt?  That magically applies str()
> to its arguments before invoking sys.stdout.write.

Guido had it right, I'm using IDLE. Actually, I thought from the tutorial that
it
shouldn't work, but it did when I used it by mistake, that's why I called it an
"inconsistency" rather than a bug.

Sorry to "bug" everyone...

And thanks for setting up the bug report form on the web page.