June 9, 2012
8:02 p.m.
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.