On Mon, Jun 15, 2020 at 8:31 PM Steven D'Aprano <steve@pearwood.info> wrote:
On Fri, Jun 12, 2020 at 09:01:33AM +0100, Rob Cliffe via Python-Dev wrote:
> 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.

Of course it is. The whole point of the REPL is to evaluate an
expression and have the result printed. (That's the P in REPL :-)

`stdout.write(...)` is an expression that returns a value, so the REPL
prints it.

The expected behavior, at least for me until I read this thread, was that the REPL would print the result of a *bare* expression, meaning when the complete statement entered is an expression when taken as a whole.

In other words, I would expect the following input and output in Python 3:

>>> sys.stdout.write('\r1')
12
>>> for i in range(1, 11):
...    sys.stdout.write('\r%d' % i)
...    time.sleep(1)
10>>>

because the first statement is, as a whole, a single expression and thus should print its result, but a for statement and block is not a single expression taken as a whole and therefore should not print intermediate (or final) results.