<p>Calling detach() on the standard streams is a bad idea - the interpreter uses the originals internally, and calling detach() breaks them. </p>
<p>--<br>
Sent from my phone, thus the relative brevity :) </p>
<div class="gmail_quote">On Jun 10, 2012 6:03 AM, "Serhiy Storchaka" <<a href="mailto:storchaka@gmail.com">storchaka@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
On 09.06.12 12:55, Nick Coghlan wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
So, after much digging, it appears the *right* way to replace a<br>
standard stream in Python 3 after application start is to do the<br>
following:<br>
<br>
     sys.stdin = open(sys.stdin.fileno(), 'r',<new settings>)<br>
     sys.stdout = open(sys.stdout.fileno(), 'w',<new settings>)<br>
     sys.stderr = open(sys.stderr.fileno(), 'w',<new settings>)<br>
</blockquote>
<br>
    sys.stdin = io.TextIOWrapper(sys.stdin.<u></u>detach(), <new settings>)<br>
    sys.stdout = io.TextIOWrapper(sys.stdout.<u></u>detach(), <new settings>)<br>
    ...<br>
<br>
None of these methods are not guaranteed to work if the input or output have occurred before.<br>
<br>
______________________________<u></u>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" target="_blank">Python-ideas@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/python-ideas" target="_blank">http://mail.python.org/<u></u>mailman/listinfo/python-ideas</a><br>
</blockquote></div>