[Python-ideas] Replacing the standard IO streams (was Re: changing sys.stdout encoding)
Nick Coghlan
ncoghlan at gmail.com
Sun Jun 10 04:26:17 CEST 2012
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 at 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 at python.org
> http://mail.python.org/**mailman/listinfo/python-ideas<http://mail.python.org/mailman/listinfo/python-ideas>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20120610/746abf52/attachment.html>
More information about the Python-ideas
mailing list