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

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


Bugs item #635814, was opened at 2002-11-08 18: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: Nobody/Anonymous (nobody)
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: kris kvilekval (kgk)
Date: 2002-11-09 13: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 10: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