[Python-Dev] Printing and __unicode__

Guido van Rossum guido@python.org
Wed, 13 Nov 2002 15:32:32 -0500

> > Though it acts somewhat as if its default encoding is "ascii".  This
> > is somewhat inconsistent: you can write arbitrary Unicode strings, but
> > the Unicode won't be converted to ASCII.  ASCII is converted to
> > Unicode though.
> It is the only case of a "pure Unicode" stream in Python, where the
> underlying "native" sequence is not one of bytes, but one of Unicode
> characters.
> The real problem is that the "orientation" (wide or narrow strings) is
> determined by the things written into the stream.
> It might be more reasonable to have StringIO.ByteIO and
> StringIO.UnicodeIO constructors, which both accept an encoding=
> argument, and will convert objects of the wrong "orientation"
> using that encoding (defaulting to the system encoding).

I'm not sure about those names, but I agree that the encoding should
be forced when the StringIO instance is created.  Given that using
Unicode with these is currently fragile at best, maybe we should say
that unless you give an encoding argument, it's a byte stream and
doesn't allow Unicode at all?  That would be consistent with cStringIO.

--Guido van Rossum (home page: http://www.python.org/~guido/)