On 6/12/20 4:01 AM, Rob Cliffe via Python-Dev wrote: > If I run the following program (using Python 3.8.3 on a Windows 10 > laptop): > > import sys, time > for i in range(1,11): > sys.stdout.write('\r%d' % i) > time.sleep(1) > > As intended, it displays '1', replacing it at 1-second intervals with > '2', '3' ... '10'. > > Now run the same code inside the REPL: > > Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 > 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys, time > >>> for i in range(1,11): > ... sys.stdout.write('\r%d' % i) > ... time.sleep(1) > ... > 12 > 22 > 32 > 42 > 52 > 62 > 72 > 82 > 92 > 103 > >>> > > It appears that the requested characters are output, *followed by* the > number of characters output > (which is the value returned by sys.stdout.write) and a newline. > Surely this is not the intended behaviour. > sys.stderr behaves the same as sys.stdout. > > Python 2 does NOT exhibit this behaviour: > > Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:19:08) [MSC v.1500 > 32 bit (Intel)] on win32 > Type "help", "copyright", "credits" or "license" for more information. > >>> import sys, time > >>> for i in range(1,11): > ... sys.stdout.write('\r%d' % i) > ... time.sleep(1) > ... > 10>>> > # displays '1', '2' ... '10' as intended. > > Best wishes > Rob Cliffe Is that what the REPL is defined to do? print the results of each statement (unless it is None), so when working on it you don't need to say print(...) everywhere.
-- Richard Damon _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/6QP2IUW6ZDYGUFUZNEORX3BPRMCSBWOF/ Code of Conduct: http://python.org/psf/codeofconduct/