Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #94808

Interactive entered code, inserts spurious numbers.

Date 2015-07-31 10:47 +0200
From Antoon Pardon <antoon.pardon@rece.vub.ac.be>
Subject Interactive entered code, inserts spurious numbers.
Newsgroups comp.lang.python
Message-ID <mailman.1114.1438332507.3674.python-list@python.org> (permalink)

Show all headers | View raw


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.

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Interactive entered code, inserts spurious numbers. Antoon Pardon <antoon.pardon@rece.vub.ac.be> - 2015-07-31 10:47 +0200
  Re: Interactive entered code, inserts spurious numbers. Steven D'Aprano <steve@pearwood.info> - 2015-07-31 19:30 +1000

csiph-web