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" <[EMAIL PROTECTED]> 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/)
_______________________________________________
Python-3000 mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to