[Python-Dev] why doesn't print pass unicode strings on to the file object?

Martin von Loewis loewis@informatik.hu-berlin.de
Thu, 6 Sep 2001 18:56:57 +0200 (MEST)


> is there any reason why "print" cannot pass unicode
> strings on to the underlying write method?

Mostly because there is no guarantee that every .write method will
support Unicode objects. I see two options: either a stream might
declare itself as supporting unicode on output (by, say, providing a
unicode attribute), or all streams are required by BDFL pronouncement
to accept Unicode objects.

BTW, your wrapper example can be rewritten as

import sys,codecs
sys.stdout = codecs.lookup("iso-8859-1")[3](sys.stdout)

I wish codecs.lookup returned a record with named fields, instead of a
list, so I could write

sys.stdout = codecs.lookup("iso-8859-1").writer(sys.stdout)

(the other field names would be encode,decode, and reader).

Regards,
Martin