[Python-ideas] Replacing the standard IO streams (was Re: changing sys.stdout encoding) (original) (raw)
Serhiy Storchaka storchaka at gmail.com
Sat Jun 9 22:02:19 CEST 2012
- Previous message: [Python-ideas] Replacing the standard IO streams (was Re: changing sys.stdout encoding)
- Next message: [Python-ideas] Replacing the standard IO streams (was Re: changing sys.stdout encoding)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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',) sys.stdout = open(sys.stdout.fileno(), 'w',) sys.stderr = open(sys.stderr.fileno(), 'w',)
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.
- Previous message: [Python-ideas] Replacing the standard IO streams (was Re: changing sys.stdout encoding)
- Next message: [Python-ideas] Replacing the standard IO streams (was Re: changing sys.stdout encoding)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]