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

Fredrik Lundh fredrik@pythonware.com
Thu, 6 Sep 2001 18:11:48 +0200


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

it would be really nice if this piece of code worked as
expected:

import sys

class Wrapper:
    def __init__(self, file):
        self.file =3D file
    def write(self, data):
        self.file.write(data.encode("iso-8859-1", "replace"))

sys.stdout =3D Wrapper(sys.stdout)

print u"=E5=E4=F6"

under 2.2a2 (and earlier versions), this gives me:

Traceback (most recent call last):
  File "\test.py", line 8, in ?
    print u"=E5=E4=F6"
UnicodeError: ASCII encoding error: ordinal not in range(128)

(I'm willing to implement this, if the BDFL says so)

</F>