[Python-3000] Does Py3k's print offer any unicode encoding help?

Guido van Rossum guido at python.org
Sat Feb 16 03:11:39 CET 2008


In general these things are only safe when done before any I/O happens.

But even so it's only a stop-gap measure; the app shouldn't have to do
this, we should fix the guessing algorithm.

On Fri, Feb 15, 2008 at 5:03 PM, "Martin v. Löwis" <martin at v.loewis.de> wrote:
> > 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
>



-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list