cStringIO.StringIO has no write method?

Laszlo Nagy gandalf at designaproduct.biz
Tue Jul 25 15:36:40 EDT 2006


>>     
> Nope. StringI is an input-only object, StringO is an output object. You 
> got a StringI because you gave a string argument to the creator.
>
>
>  >>> f1 = cStringIO.StringIO()
>  >>> f1
> <cStringIO.StringO object at 0x186c9c00>
>  >>> dir(f1)
> ['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', 
> '__init__', '__iter__', '__new__', '__reduce__', '__reduce_ex__', 
> '__repr__', '__setattr__', '__str__', 'close', 'closed', 'flush', 
> 'getvalue', 'isatty', 'next', 'read', 'readline', 'readlines', 'reset', 
> 'seek', 'softspace', 'tell', 'truncate', 'write', 'writelines']
>  >>> f2 = cStringIO.StringIO("This is the fixed content of the StringIO")
>  >>> f2
> <cStringIO.StringI object at 0x18661440>
>  >>> dir(f2)
> ['__class__', '__delattr__', '__doc__', '__getattribute__', '__hash__', 
> '__init__', '__iter__', '__new__', '__reduce__', '__reduce_ex__', 
> '__repr__', '__setattr__', '__str__', 'close', 'closed', 'flush', 
> 'getvalue', 'isatty', 'next', 'read', 'readline', 'readlines', 'reset', 
> 'seek', 'tell', 'truncate']
>  >>>
>   
Is it possible to have a direct access in-memory file that can be 
written and read too?

   Laszlo




More information about the Python-list mailing list