Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; '*not*': 0.07; 'defaults': 0.07; 'bug.': 0.09; 'feature,': 0.09; 'finished.': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; '"="': 0.16; '(assuming': 0.16; 'loops': 0.16; 'of)': 0.16; 'semantics': 0.16; 'wrote:': 0.18; '(not': 0.18; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply- To:1': 0.27; 'statement': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; "d'aprano": 0.31; 'steven': 0.31; 'probably': 0.32; 'fri,': 0.33; "i'd": 0.34; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'introducing': 0.36; 'keyword': 0.36; 'useful': 0.36; 'break': 0.61; 'introduced': 0.61; 'new': 0.61; 'july': 0.63; 'skip:n 10': 0.64; 'jul': 0.74; 'introduce': 0.78; '*really*': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=NlwbsOlAXNhf19IR5t/1y7dU9kjFrnyMZeHP14D7/Vk=; b=VoYB1zuxUg1GD5skkuP/Uygr3xhjyhNUPbpfwm3TKbV1eF2EJoaTHi3g40EVPE8ppQ oWQkmU9/3CT5De4BqDExTHCT7Zy25LoqUQnzTy+149GiEs6BEA9nNX1W91jP8bdRylc7 iVf0V2W1udmUTyEzN1/CLeUqC7iQ90DgVtNqSfDEnVl8T6TxhrDueoYFq7hELPiQ6FNB Y6UzQ3gjTSrdPVWLvlNA9vGm8Am8mdzqPslmWMgfKObGxk1Eyb8/UCS3gbuhc32u+e+k X1wbVD0rKmg96AOfPmEQCMXaZT0NWV/zx//yw3i94FqomtXrlwuoWwQYTdzjCKDrvPi+ a5hA== X-Received: by 10.112.5.199 with SMTP id u7mr10738893lbu.67.1373289296517; Mon, 08 Jul 2013 06:14:56 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <51d4eb9c$0$29999$c3e8da3$5496439d@news.astraweb.com> <51d508ed$0$6512$c3e8da3$5496439d@news.astraweb.com> <51d9929b$0$9505$c3e8da3$5496439d@news.astraweb.com> From: Joshua Landau Date: Mon, 8 Jul 2013 14:14:16 +0100 Subject: Re: Default scope of variables To: Neil Cerutti Content-Type: text/plain; charset=UTF-8 Cc: python-list X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373289303 news.xs4all.nl 15973 [2001:888:2000:d::a6]:45105 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50155 On 8 July 2013 12:54, Neil Cerutti wrote: > On 2013-07-07, Steven D'Aprano wrote: >> On Fri, 05 Jul 2013 13:24:43 +0000, Neil Cerutti wrote: >> >>> for x in range(4): >>> print(x) >>> print(x) # Vader NOoooooOOOOOO!!! >> >> That loops do *not* introduce a new scope is a feature, not a bug. It is >> *really* useful to be able to use the value of x after the loop has >> finished. > > I don't buy necessarily buy that it's "*really*" useful Just take "really" to mean "like, I'm totz not lying". > but I do > like introducing new names in (not really the scope of) > if/elif/else and for statement blocks. > > z = record["Zip"] > if int(z) > 99999: > zip_code = z[:-4].rjust(5, "0") > zip4 = z[-4:] > else: > zip_code = z.rjust(5, "0") > zip4 = "" I'd probably break down and cry if "if"s introduced a new scope in Pythons before the "nonlocal" keyword (assuming current Python semantics where "=" defaults to only the inner-most scope).