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


Groups > comp.lang.python > #94808

Interactive entered code, inserts spurious numbers.

Path csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed7.news.xs4all.nl!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <antoon.pardon@rece.vub.ac.be>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'received:134': 0.05; 'sys': 0.05; 'executed': 0.07; 'subject:code': 0.07; 'interpreter,': 0.09; 'loop.': 0.09; 'python': 0.10; 'interpreter': 0.15; 'result.': 0.15; 'received:ac.be': 0.16; 'result:': 0.16; 'math': 0.20; 'import': 0.24; 'written': 0.24; 'header:User-Agent:1': 0.26; 'behaviour': 0.29; 'code:': 0.29; "i'm": 0.30; 'code': 0.30; 'received:be': 0.30; 'guess': 0.31; 'file': 0.34; 'gives': 0.35; 'expected': 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'being': 0.37; 'to:addr:python.org': 0.40; 'different': 0.63; '(a,': 0.84; '=====': 0.84
X-IronPort-Anti-Spam-Filtered true
X-IronPort-Anti-Spam-Result AqkHAM41u1WGuA9G/2dsb2JhbABbhDIBg0e+QIRZAQEBAQEBhVhVKgwCBRYLAgsDAgECAUsNCAKIKqBsj1+RIYUTgSKSI4FDBZR4jEmISpB1JoFKgjWDOQEBAQ
Date Fri, 31 Jul 2015 10:47:13 +0200
From Antoon Pardon <antoon.pardon@rece.vub.ac.be>
User-Agent Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Icedove/31.7.0
MIME-Version 1.0
To Pyton List <python-list@python.org>
Subject Interactive entered code, inserts spurious numbers.
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1114.1438332507.3674.python-list@python.org> (permalink)
Lines 51
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1438332507 news.xs4all.nl 2924 [2001:888:2000:d::a6]:44396
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:94808

Show key headers only | 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