unicode question
"Martin v. Löwis"
martin at v.loewis.de
Mon Nov 22 18:24:09 EST 2004
Bengt Richter wrote:
> So, bottom line, as Wolfgang effectively asked by his example, why does print try to coerce
> the __str__ return value to ascii on the way to the ouput encoder, when there is encoding info
> in the unicode object that it is happy to defer reencoding of for sys.stdout.encoding?
[See my other posting:]
Because print invokes str() on its argument, unless the argument is
already a byte string (in which case it prints it directly), or a
Unicode string (in which case it encodes it with the stream encoding).
It is str(y) that fails, not the printing.
Regards,
Martin
More information about the Python-list
mailing list