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

tim_one@email.msn.com tim_one@email.msn.com
Fri, 3 Dec 1999 22:45:22 -0500 (EST)


> 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.