cStringIO write

Robin Becker robin at jessikat.fsnet.co.uk
Sat Apr 13 09:20:11 EDT 2002


Is it deliberate that 2.2 cStringIO only has a write method when created uninitialised? StringIO
doesn't have this 'feature', but no mention is made of this in the docs.

>>> import StringIO, cStringIO
>>> y = cStringIO.StringIO('aaa')
>>> dir(y)
['close', 'flush', 'getvalue', 'isatty', 'read', 'readline', 'readlines', 'reset', 'seek',
'tell', 'truncate']
>>> y.write('aaaa')
Traceback (most recent call last):
  File "<interactive input>", line 1, in ?
AttributeError: write
>>> z = cStringIO.StringIO()
>>> z.write('aaaa')
>>> dir(z)
['close', 'flush', 'getvalue', 'isatty', 'read', 'readline', 'readlines', 'reset', 'seek',
'tell', 'truncate', 'write', 'writelines']
>>> y = StringIO.StringIO('aaa')
>>> dir(y)
['__doc__', '__init__', '__iter__', '__module__', 'buf', 'buflist', 'close', 'closed', 'flush',
'getvalue', 'isatty', 'len', 'pos', 'read', 'readline', 'readlines', 'seek', 'softspace',
'tell', 'truncate', 'write', 'writelines']
>>> y.write('aaaa')
>>> z = cStringIO.StringIO()
>>> z.write('aaaa')
>>> dir(z)
['close', 'flush', 'getvalue', 'isatty', 'read', 'readline', 'readlines', 'reset', 'seek',
'tell', 'truncate', 'write', 'writelines']
>>> 
-- 
Robin Becker



More information about the Python-list mailing list