[Python-3000] Does Py3k's print offer any unicode encoding help?
"Martin v. Löwis"
martin at v.loewis.de
Sat Feb 16 02:03:33 CET 2008
> I think you're on to something. There's an API to access the
> underlying (buffered) binary stream: sys.stdout.buffer. It's possible
> to create a new TextIOWrapper on top of that:
>
> sys.stdout = io.TextIOWrapper(sys.stdout.buffer, "utf-8")
While it might be possible to switch an output stream that way, it's
fairly difficult to do that correctly for input, no? The wrapper
may have already read data from the underlying stream which have not
been given to the application. If you don't want to lose these
data, you either need to copy them over to the new stream, or unread
them from the underlying buffer. That's tricky as some of the data might
be in the codec.
Regards,
Martin
More information about the Python-3000
mailing list