
On 10 June 2012 19:12, MRAB <python@mrabarnett.plus.com> wrote:
On 10/06/2012 17:41, Stephen J. Turnbull wrote:
I am a little concerned with MRAB's report that
import sys print("hello") sys.stdout.flush() sys.stdout = open(sys.stdout.fileno(), 'w', encoding='utf-8') print("hello")
doesn't work as expected, though. (It does work for me on Mac OS X, both as above -- of course there are no '\r's in the output -- and with 'print("hello", end="\r\n")'.)
That's actually Python 3.1. From Python 3.2 it's slightly different, but still not quite right:
Python 3.1: "hello\r\nhello\r\r\n" Python 3.2: "hello\nhello\r\n" Python 3.3.0a4: "hello\nhello\r\n"
All on Windows.
Not here (Win 7 32-bit): PS D:\Data> type t.py import sys print("Hello!") sys.stdout.flush() sys.stdout = open(sys.stdout.fileno(), 'w', encoding='utf-8') print("Hello!") PS D:\Data> py -3.2 t.py | od -c 0000000 H e l l o ! \r \n H e l l o ! \r \n 0000020 Paul.