[Python-bugs-list] [ python-Bugs-635814 ] cStringIO().write TypeError

noreply@sourceforge.net noreply@sourceforge.net
Sat, 09 Nov 2002 13:35:05 -0800


Bugs item #635814, was opened at 2002-11-09 03:30
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=635814&group_id=5470

Category: Python Library
Group: Python 2.2.2
Status: Open
Resolution: None
Priority: 5
Submitted By: kris kvilekval (kgk)
>Assigned to: M.-A. Lemburg (lemburg)
Summary: cStringIO().write TypeError

Initial Comment:


There is an incompatibilty between StringIO and 
cStringIO, as demonstrated below..  Passing an
integer to StringIO.write is OK while
it not OK to pass one to cStringIO.

$ python
Python 2.2.2 (#4, Oct 15 2002, 04:21:28) 
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for
more information.
>>> import StringIO
>>> sfile = StringIO.StringIO()
>>> sfile.write (100)
>>> print sfile.getvalue()
100
>>> import cStringIO
>>> cfile = cStringIO.StringIO()
>>> cfile.write (100)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
TypeError: write() argument 1 must be string or
read-only buffer, not int
>>> cfile.write (str(100))


----------------------------------------------------------------------

>Comment By: Martin v. L÷wis (loewis)
Date: 2002-11-09 22:35

Message:
Logged In: YES 
user_id=21627

It's a bug that StringIO accepts it. file.write does not
support numbers, either. Unfortunately, this bug cannot be
fixed, for backwards compatibility. The conversion of any
argument to a string was originally introduced for Python
2.2, to support arbitrary buffer objects. That it also
accepts numbers now was an unexpected side effect.

Assigning to Marc-Andre, as he introduced that feature
originally.

----------------------------------------------------------------------

Comment By: kris kvilekval (kgk)
Date: 2002-11-09 22:09

Message:
Logged In: YES 
user_id=569286

This seems like an unnecessary incompatibility,
however I guess it is there in the interest of speed?

----------------------------------------------------------------------

Comment By: Martin v. L÷wis (loewis)
Date: 2002-11-09 19:04

Message:
Logged In: YES 
user_id=21627

This is by design. The file protocol makes no guarantee that
you can write objects other than strings into a file, unless
the object explicitly documents the support for other objects.

cStringIO differs in many ways from StringIO, this is but
one way.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=635814&group_id=5470