Calling detach() on the standard streams is a bad idea - the interpreter uses the originals internally, and calling detach() breaks them.

--
Sent from my phone, thus the relative brevity :)

On Jun 10, 2012 6:03 AM, "Serhiy Storchaka" <storchaka@gmail.com> wrote:
On 09.06.12 12:55, Nick Coghlan wrote:
So, after much digging, it appears the *right* way to replace a
standard stream in Python 3 after application start is to do the
following:

    sys.stdin = open(sys.stdin.fileno(), 'r',<new settings>)
    sys.stdout = open(sys.stdout.fileno(), 'w',<new settings>)
    sys.stderr = open(sys.stderr.fileno(), 'w',<new settings>)

   sys.stdin = io.TextIOWrapper(sys.stdin.detach(), <new settings>)
   sys.stdout = io.TextIOWrapper(sys.stdout.detach(), <new settings>)
   ...

None of these methods are not guaranteed to work if the input or output have occurred before.

_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
http://mail.python.org/mailman/listinfo/python-ideas