Interactive entered code, inserts spurious numbers.

Antoon Pardon antoon.pardon at rece.vub.ac.be
Fri Jul 31 04:47:13 EDT 2015


I'm using python 3.4.2 on debian 8.

This is the code:

==== 8< =====

import sys
write = sys.stdout.write

from math import pi

frac = 3
for a in range(2 * frac):
    write("%2d: %6.4f\n" % (a, a * pi / frac))

===== 8< ====

Now when this code is written in a file and executed
I get the expected result:

 0: 0.0000
 1: 1.0472
 2: 2.0944
 3: 3.1416
 4: 4.1888
 5: 5.2360

But when I enter this code interactively in the interpreter
I get the following result:

 0: 0.0000
11
 1: 1.0472
11
 2: 2.0944
11
 3: 3.1416
11
 4: 4.1888
11
 5: 5.2360
11

That is different behaviour from python2, which gives me
the expected result. My guess is that the write returns
11, being the number of characters written en that the
interpreter, shows that each time through the loop.

But is this the expected behaviour in python3? I find
it annoying.




More information about the Python-list mailing list