[Python-Dev] Printing and __unicode__

Martin v. Loewis martin@v.loewis.de
12 Nov 2002 20:12:09 +0100


Guido van Rossum <guido@python.org> writes:

> > B. A file indicates "unicode-awareness" somehow. For a Unicode-aware
> >    file, it tries __unicode__, __str__, and __repr__, in order.
> 
> I like this.

Ok, then the question is: How can a file indicate its
unicode-awareness? I propose that presence of an attribute "encoding"
is taken as such an indication; this would cover all existing cases
with no change to the file-like objects. 

In case the stream is "natively" Unicode (i.e. doesn't ever convert to
byte strings), setting encoding to None should be allowed (this
actually indicates that StringIO should have the encoding attribute).

Regards,
Martin