[I18n-sig] Re: [Python-Dev] Unicode debate

Fredrik Lundh Fredrik Lundh" <effbot@telia.com
Thu, 4 May 2000 09:46:05 +0200

Ka-Ping Yee <ping@lfw.org> wrote:
> I know this is not a small change, but i'm pretty convinced the
> right answer here is that the print hook should call a *method*
> on sys.stdout, whatever sys.stdout happens to be.  The details
> are described in the other long message i wrote ("Printing objects
> on files").
> Here is an addendum that might actually make that proposal
> feasible enough (compatibility-wise) to fly in the short term:
>     print x
> does, conceptually:
>     try:
>         sys.stdout.printout(x)
>     except AttributeError:
>         sys.stdout.write(str(x))
>         sys.stdout.write("\n")
> The rest can then be added, and the change in 'print x' will
> work nicely for any file objects, but will not break on file-like
> substitutes that don't define a 'printout' method.

another approach is (simplified):

    except AttributeError:

or, if str is changed to return any kind of string:

    x =3D str(x)
        x =3D x.encode(sys.stdout.encoding)
    except AttributeError: