StringIO + unicode

Diez B. Roggisch deets at nospam.web.de
Tue Mar 25 05:56:43 EDT 2008


Laszlo Nagy wrote:

> Is there a standard "in-memory file" interface for reading/writting
> unicode stings? Something like StringIO.
> 
> E.g. this would be possible:
> 
> - create UnicodeStringIO
> - write unicode strings into it
> - wite data (binary) string of UnicodeStringIO into a file ('wb' mode)
> 
> and then later:
> 
> - read the same file with codecs.open(filename,"r",encoding="utf-8")
> 
> Maybe there is no standard class for this and I have to implement it
> myself. (?)

Never tried it, but can't you just combine StringIO + codecs-module, the
latter offers a wrapping-service for streams.

Diez



More information about the Python-list mailing list