Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Chris Angelico Newsgroups: comp.lang.python Subject: Re: for / while else doesn't make sense Date: Tue, 24 May 2016 03:33:55 +1000 Lines: 41 Message-ID: References: <573f9322$0$1616$c3e8da3$5496439d@news.astraweb.com> <5741cde9$0$1587$c3e8da3$5496439d@news.astraweb.com> <57422e03$0$1596$c3e8da3$5496439d@news.astraweb.com> <85r3ct9zt2.fsf@benfinney.id.au> <5742bacb$0$1526$c3e8da3$5496439d@news.astraweb.com> <87zirgrgol.fsf@bsb.me.uk> <574336f5$0$1600$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de Z3LcCpHgPi9YYNQ/9L1SaQyrmaJHd7oi5HZ5lcG7zFMg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'cc:addr:python-list': 0.09; 'rounds': 0.09; 'subject:while': 0.09; 'subtle': 0.09; 'bug': 0.10; 'python': 0.10; '2016': 0.16; '24,': 0.16; 'decimal.': 0.16; 'expects': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:make': 0.16; 'useless': 0.16; 'wrote:': 0.16; 'string': 0.17; 'integer': 0.18; '>>>': 0.20; 'people,': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'fraction': 0.22; 'int,': 0.22; 'am,': 0.23; 'import': 0.24; 'header:In-Reply-To:1': 0.24; 'earlier': 0.27; 'bugs': 0.27; 'message-id:@mail.gmail.com': 0.27; 'another.': 0.29; 'division': 0.29; 'code:': 0.29; 'changed': 0.33; 'common': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'tue,': 0.34; 'received:google.com': 0.35; 'options:': 0.35; 'received:74.125.82': 0.35; 'but': 0.36; 'there': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'why': 0.39; 'where': 0.40; 'your': 0.60; 'making': 0.62; 'subject: / ': 0.63; 'more': 0.63; 'deeply': 0.64; 'special': 0.73; '*every': 0.84; 'chrisa': 0.84; 'float,': 0.84; 'short-hand': 0.84; 'subject:else': 0.84; 'subject:sense': 0.84; 'to:none': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc; bh=wbPioHiqKcDdpKUcH9MZ+7K8tQ+OgkTsgWmbCQ4FmUo=; b=wiYGlLqITqWAEWOUX8IIqCBNLwp0SxGoIfTbYbLzeWzI59g6ONFYb/jwd+FWulAzbg aed2DsNIi7VXuDcyXZ5IADtSF2jOF5ewIhXdbP0fC/EXorln8kbz+U9B0MKlDo9Edpzs tg8WP93GK30go4flLaf9Ld+8BvOgBLoROlVOqAMBUoS4wBlQyayX1ifE40zReyQtdKyD mkWO0UCf7AHdlUNvciH0uRv9dAgpTuv5oCSnjYLSGGIXuwaCgEmYeZEmLu0Xqq0vGwJc 0nj1p+2fRzl6ojl5UeRg6w6XL+KKWyK6aGkFBYe5Y3gCwStr1pJBYT/e1tEClh39wG+4 gXYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:cc; bh=wbPioHiqKcDdpKUcH9MZ+7K8tQ+OgkTsgWmbCQ4FmUo=; b=jHZdI/pYe4T2ojMiyDeoLxBfME4vwAjsYhFGqHdMCwtaV8tvDz0szVsb7L92kTvY1e 6iDOfMMdlYh0efIFK3HIrYbau+8gMfAm9e1BNHj6DJKmW9XPeVMMLS7/eNgdd7uIx6RT Oem/e1UzYiy7M2O2TXw4bSHlUU8EqNHEPwtzpZwsk6kpK2Wa9Z+NueomcbfOdVqlqulP QLSHEo9OQX74qY7xTNVVRMCPLJNKEoI9DiUGIcXtTCaJNttwVajw71hKchtCazvIX7qf T3GZvW4/g8jcSYzhdvN0HumPfYNcy52RVX5balbbWcuUEnAyMhQfKxSNCRyySqy9lGjR G+ag== X-Gm-Message-State: ALyK8tLcKRWR3bPC00gNmxGJPXsnoew/098zLgtGUAh5+yruwNz8QaISYZYcT8zyUR3ZL+v2D/q/oG1Fm7PWJA== X-Received: by 10.194.91.194 with SMTP id cg2mr11050wjb.47.1464024836283; Mon, 23 May 2016 10:33:56 -0700 (PDT) In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <573f9322$0$1616$c3e8da3$5496439d@news.astraweb.com> <5741cde9$0$1587$c3e8da3$5496439d@news.astraweb.com> <57422e03$0$1596$c3e8da3$5496439d@news.astraweb.com> <85r3ct9zt2.fsf@benfinney.id.au> <5742bacb$0$1526$c3e8da3$5496439d@news.astraweb.com> <87zirgrgol.fsf@bsb.me.uk> <574336f5$0$1600$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:109013 On Tue, May 24, 2016 at 3:09 AM, Jon Ribbens wrote: > On 2016-05-23, Steven D'Aprano wrote: >> But one thing is certain: very few people, Jon Ribbens being one of them, >> expects 1/3 to return 0. And that is why Python changed the meaning of >> the / operator: because using it for integer division was deeply unpopular >> and a bug magnet. > > Making it return floats is also a bug magnet, just for more subtle > bugs that are harder to diagnose. See my earlier post. There are four broadly-viable options: int, float, Fraction, Decimal. *Every one of them* is a bug magnet in one way or another. Which kind of bug would you like? * 1235678678/3 == 411892892 * (1/3) + (1/3) + (1/3) != 1 * x != x + 0 * useless reprs after a few rounds of addition Take your pick. :) By the way, did you know that Python has support for fraction literals? Just put this at the top of your code: import fractions; f = fractions.Fraction(1) and then you can use the special "tagged literal" syntax, like with special forms of string literal: >>> f*22/7 + f*2/11 Fraction(256, 77) There's even a short-hand form for the common case where the numerator is 1: >>> f/2 + f/3 Fraction(5, 6) Very handy, particularly interactively. :) ChrisA