Path: csiph.com!weretis.net!feeder4.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!newsfeed0.kamp.net!newsfeed.kamp.net!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: Fri, 20 May 2016 06:01:23 +1000 Lines: 26 Message-ID: References: <573dfc0f$0$1586$c3e8da3$5496439d@news.astraweb.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de AlpnOfgicq//oVeS9u5VPQMfT/mW20YoWhU/qeXCPODw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'finally:': 0.05; 'executed': 0.07; 'cc:addr:python-list': 0.09; 'exception:': 0.09; 'executes': 0.09; 'subject:while': 0.09; 'example:': 0.10; 'things.': 0.15; '*almost*': 0.16; '2016': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'run.': 0.16; 'subject:make': 0.16; 'wrote:': 0.16; 'try:': 0.18; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'header:In-Reply- To:1': 0.24; 'fri,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'idea': 0.28; 'guarantees': 0.29; 'loop,': 0.29; 'code': 0.30; '[1]': 0.32; 'run': 0.33; "d'aprano": 0.33; 'steven': 0.33; 'except': 0.34; 'gets': 0.35; 'received:google.com': 0.35; 'received:74.125.82': 0.35; 'subject:: ': 0.37; 'chance': 0.60; 'matter': 0.63; 'subject: / ': 0.63; '20,': 0.66; 'guaranteed': 0.67; 'finally': 0.70; 'power': 0.72; 'chrisa': 0.84; 'subject:else': 0.84; 'subject:sense': 0.84; 'absolutely': 0.88; '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=oJVLhIceJdJl9rwLUiWJkoGNW+gkBkJy5YofJIQsTjw=; b=IABtQR/HSnbLOTQLNHlRIGPoe7MM7aWDma0Ut/bK2326r8KXdD4l63G0x6GscS9ZCz /4Mm1cbIsvr9zuA5LdbpaJgZ5UrNz++kT0mY9GOVcJ5cn0EJQu5GMQP+bUbUxmVju2b1 uw0hU1zQczOrVJYAVl+OxmeFbzZ3P0x9dqkysDYK5JPjSGcdviuBHsIFXh+myJziGP7s qxa47/8mgQGhk21l65AY+YutoEiGSnK4EI4LCo/YF7gwYfQ11xqYpiSwD6G/dW5B2yu7 S9xFL29elHDKaj4YRwqxTXsT48/YkKtpj49N7J7OxpaGrDYCH4K5KmwleC54h6RRJ3Dy 9KGg== 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=oJVLhIceJdJl9rwLUiWJkoGNW+gkBkJy5YofJIQsTjw=; b=lu1wpwTn8tdrBZR6+3ghuNTcSXqHqtdpz1MnQY+ACZHqkLLCYVkvJeDlJGA1dyRAb5 Hf2fyHVLJvavI4AP92b2sHTgk0Z4Qs7d7gROaiyJdmVGrM51qoJllsgnRIOziQHKWMIb aa3H0izy+egRlgVWuDBe/vv81n7QMJJDX2yqD7C8MwHAusAubsy7e/CnCaF+Cr0hl6Bn +FJB6lWYHgoZd7sImeKbPlqX1IYYigl3km//5l6tRPFJC73kB4FexLD+u1EapIcYVjAU baIUhorpHJVN31QpDIBkU/Y2RjWg3zX6yYOxmw32BGKsKz3Qw6lZPazDtXQ68zm3eT86 f5bA== X-Gm-Message-State: AOPr4FVICnoE852uYlBYJ98a0m7W65JHPKMDgGjj6SKh92vKESbkk93TjtYtQwn6X8VsfsQoIHNoQuYncGSdrg== X-Received: by 10.28.44.87 with SMTP id s84mr15121578wms.61.1463688083718; Thu, 19 May 2016 13:01:23 -0700 (PDT) In-Reply-To: <573dfc0f$0$1586$c3e8da3$5496439d@news.astraweb.com> 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: <573dfc0f$0$1586$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:108838 On Fri, May 20, 2016 at 3:46 AM, Steven D'Aprano wrote: > The idea of finally is > that it executes no matter what happens[1]. > > [1] Well, *almost* no matter what. If you pull the power from the computer, > the finally block never gets a chance to run. Nor if you kill -9 the process, or get into an infinite loop, or any number of other things. Specifically, what the finally block guarantees is that it will be executed *before any code following the try block*. In this example: try: code1 except Exception: code2 else: code3 finally: code4 code5 Once you hit code1, you are absolutely guaranteed that code5 *will not* be run prior to code4. ChrisA