When StringIO gets an initial value passed to its constructor, it seems to discard it after the first call to .write(). For instance:

>>> from StringIO import StringIO
>>> buffer = StringIO('foo')
>>> buffer.getvalue()
'foo'
>>> buffer.write('bar')
>>> buffer.getvalue()
'bar'
>>> buffer.write('baz')
>>> buffer.getvalue()
'barbaz'

The obvious workaround is to call buffer.write() with the initial value instead of passing it to StringIO's constructor, so this issue doesn't bother me very much, but I'm still curious about it. Is this the expected behavior, and why it isn't mentioned in the docs if so?
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to