[Python-Dev] Printing and __unicode__

Guido van Rossum guido@python.org
Wed, 13 Nov 2002 16:17:30 -0500


> > 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.
> 
> But it would break compatibility, atleast with
> xml.dom.minidom.Node.write, which support StringIO currently, and will
> collect Unicode strings in it.

Would it be acceptable if StringIO required you to be consistent,
i.e. write only Unicode *or* only 8-bit strings, and never mix them?

That would be some kind of magical behavior; the encoding attribute
should be set to reflect the mode after the first write, and should be
None initially (or some other way to indicate the magic).

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