15 Jun
2020
15 Jun
'20
9:50 p.m.
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.
Why not? I suppose it's intended this way. A behavior change like this does not happen by accident.
for i in range(3): ... (lambda: 2)() ... 2 2 2