Looks like the python version of StringIO can write tuples, but not the C version. I am not sure this is intended: >>> from cStringIO import StringIO as cStringIO >>> from StringIO import StringIO as StringIO >>> string = StringIO() >>> string.write(('my', 'tuple')) >>> cstring = cStringIO() >>> cstring.write(('my', 'tuple')) Traceback (most recent call last): File "", line 1, in TypeError: write() argument 1 must be string or read-only character buffer, not tuple
Probably not. I guess an implicit str() is done on the argument given to write(): >>> s = StringIO() >>> s.write((1,2)) >>> s.write(3) >>> s.getvalue() '(1, 2)3'
Yes, I am not sure what would be the best fix though. We cannot raise an error on StringIO now because this will break lots of code out there. In the meantime, I think it's cleaner to avoid doing implicit str() conversions, so I think cStringIO has a better approach. I would be in favor of a status quo for 2.x