This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: StringIO() does not behave like cStringIO() when given an array object
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: pitrou, r.david.murray, santoso.wijaya
Priority: normal Keywords:

Created on 2013-03-22 01:50 by santoso.wijaya, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg184939 - (view) Author: Santoso Wijaya (santoso.wijaya) * Date: 2013-03-22 01:50
Python 2.7.3 (default, Sep 26 2012, 21:51:14) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import array, cStringIO, StringIO
>>> a = array.array('B', [1,2,3])
>>> cStringIO.StringIO(a).getvalue()
'\x01\x02\x03'
>>> StringIO.StringIO(a).getvalue()
"array('B', [1, 2, 3])"
>>>
msg184941 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-03-22 02:40
That is unfortunate, but I suspect it is not something that we can change, since it would be a change in behavior (StringIO.StringIO doing an str on its input) that existing code may be depending on.  

In Python3, StringIO doesn't accept an array as input, and BytesIO behaves the way cStringIO does in Python2.
msg184951 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2013-03-22 09:56
Indeed, this is probably too late to fix, since it only affects 2.7. Calling StringIO / cStringIO with a non-str argument should probably have raised TypeError, for the sake of sanity.
History
Date User Action Args
2022-04-11 14:57:43adminsetgithub: 61719
2013-03-22 09:56:19pitrousetstatus: open -> closed

nosy: + pitrou
messages: + msg184951

resolution: wont fix
2013-03-22 02:40:58r.david.murraysetnosy: + r.david.murray
messages: + msg184941
2013-03-22 01:50:52santoso.wijayasettype: behavior
2013-03-22 01:50:42santoso.wijayacreate