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: Fri, 20 May 2016 06:27:47 +1000 Lines: 36 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 JfnvDiXuzymuGpxePSUjQQWskvHSAoNfT0yFe9rL4eOg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; 'finally:': 0.05; 'executed': 0.07; 'exit': 0.07; 'cc:addr:python-list': 0.09; 'exception:': 0.09; 'executes': 0.09; 'subject:while': 0.09; 'example:': 0.10; 'things.': 0.15; 'thu,': 0.15; '"well,': 0.16; '*almost*': 0.16; '2016': 0.16; 'cc:name:python': 0.16; 'foul': 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; 'case.': 0.18; 'try:': 0.18; '>>>': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; 'am,': 0.23; 'passing': 0.23; 'header:In-Reply-To:1': 0.24; 'all.': 0.24; "doesn't": 0.26; 'chris': 0.26; 'fri,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; 'idea': 0.28; 'guarantees': 0.29; 'loop,': 0.29; 'that.': 0.30; '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; 'could': 0.35; 'execution': 0.35; 'received:74.125.82': 0.35; 'but': 0.36; 'possible': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'still': 0.40; 'chance': 0.60; 'matter': 0.63; 'subject: / ': 0.63; 'within': 0.64; '20,': 0.66; 'fall': 0.66; 'guaranteed': 0.67; 'finally': 0.70; 'power': 0.72; '6:11': 0.84; 'chrisa': 0.84; 'stronger': 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=3BUB8qoTQQ2tgKVnpsyKIUAVMEdqRZanY6HIdCGMgiE=; b=TggZMaMK1FbSyLsy5ZwzvwzSxA6yCc1agX92VRDsjYsSOFME/+Ol8GfL3CXRHawzUK +GSVFjoZlbhuW1w/NchauoSzvI3AZPEV5EuA5T0Ul94HoDNfLLhfETBRsXMllLcEenop eCH70j/g16bMFg6ucqdXd5FQL1pvTMw5aXq+J7A5FejpZjBoh3Xv4E/PYr3fheKttSUE LS/tE0uXWQ2KmoViQxoNBDpSI1VJfPI/x71BB+iv+UgZk47I96fBsvneJsy36q44Pxg1 9xfhcHRaRe+P7Uda4z1kFODGkuZ8oNv56WA58eV/KpmQmwtZSfJBhlyCY5GcV9EaEP0a HJVQ== 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=3BUB8qoTQQ2tgKVnpsyKIUAVMEdqRZanY6HIdCGMgiE=; b=DKeLiwUP7dH8SJ5IbozHsPyyw01AvzqoYkVdWSOTaEmwemJnp185atDakJkWd623xz C5ErQONOuG6iOFEhtUdnda9QMF5t3aSNpgdGWm0Bkauu0As4WrLKEWo1YtihyTpTLpo2 nQbrau67BmCnnNc4V7141nFF/o1SrfJ5ZWAOl3SNAXLvudAZrRL2EwFXatw9cJDciWtK d7SAElt67RI4dbd4dOXwiQjtQhzPjUNe976x1qEb1BlqS8ipWSjne+Sx5fJ63enWuYLY 0eWwYnl6rXe/NQuJxHFno8YOf03K9q6G3fyH7zbg2fOnzw3W6E8g89tbTYtx/94uPKEy aaQQ== X-Gm-Message-State: AOPr4FVfuZQ4AebHUGAHjWUAhWL9xC/HEJwNmzL6bEK6qG/cjNU5xsXKX5K9VMx/S9tlEizLpJSr6CKgTbbj1w== X-Received: by 10.28.217.72 with SMTP id q69mr5452960wmg.81.1463689667444; Thu, 19 May 2016 13:27:47 -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: <573dfc0f$0$1586$c3e8da3$5496439d@news.astraweb.com> Xref: csiph.com comp.lang.python:108842 On Fri, May 20, 2016 at 6:11 AM, Ian Kelly wrote: > On Thu, May 19, 2016 at 2:01 PM, Chris Angelico wrote: >> 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. > > The guarantee is stronger than that. It's possible to exit the try > block without passing execution to code5 at all. The finally block is > still guaranteed to be executed in this case. Yes, but I don't know how to depict "other code outside of the try block" in a way that doesn't fall foul of other nitpicks like "well, you could call that function from within the try block" :) ChrisA