Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!selfless.tophat.at!aioe.org!feeder.news-service.com!news2.euro.net!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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'compiler': 0.07; 'subject:parameters': 0.09; 'pm,': 0.10; 'debugging': 0.14; 'wrote:': 0.14; '*after*': 0.16; 'angelico': 0.16; 'confusing.': 0.16; 'subject:function': 0.16; 'compile': 0.19; 'cheers,': 0.19; 'guess': 0.19; 'header:In-Reply-To:1': 0.21; 'figure': 0.21; 'variable': 0.21; 'received:209.85.161.46': 0.23; 'received:mail- fx0-f46.google.com': 0.23; 'received:209.85.161': 0.26; 'message- id:@mail.gmail.com': 0.28; 'bound': 0.29; 'consequence': 0.30; 'sun,': 0.30; 'it.': 0.31; 'print': 0.31; 'determined': 0.32; 'to:addr:python-list': 0.33; 'error': 0.33; 'chris': 0.34; 'rule': 0.34; 'quite': 0.36; 'received:google.com': 0.37; 'received:209.85': 0.37; 'involving': 0.37; 'could': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'unless': 0.39; 'received:209': 0.39; 'to:addr:python.org': 0.39; 'storage': 0.66; 'making': 0.67; 'functioned': 0.84; 'road.': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:from:date :message-id:subject:to:content-type; bh=Ch8RbO8rWddT//rOjAwB92o25MR2Y6hAd0Ig8Ox+/qc=; b=VAp8Ms6OYKTSbkYxAgpxuTF79afrqJFYS+sZiMIvbgKom3En8MDcI4IFWx3ONupz9E Bl+kOEbWk2PLkTgCVm8ORE95xc4qU6tWK+iDm7heZWlZc/D3czeFpgU3UN/gOP3O+3dR 7h5OgYAFdeAeW/Kk/Q9drQg10fm276FQoVYA4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; b=FV8fr5R8jckzwWDk/SSzZeEutxZDY3gLbBKKuiSHcNuoje86YruIBD0TQaQgDUYkp2 /NYczLgUjRG3T1Q9tufBeNUbD/ejV9IVPfo7umtr86K3BMf2BorXti36MIa7JMgVTYF/ CK6SXcOat0d0Iu74cEyzv/h6Tnf4tiNlwYIjk= MIME-Version: 1.0 In-Reply-To: References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> From: Ian Kelly Date: Sun, 29 May 2011 13:12:16 -0600 Subject: Re: scope of function parameters To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 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: 20 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1306696368 news.xs4all.nl 49039 [::ffff:82.94.164.166]:54093 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6565 On Sun, May 29, 2011 at 12:38 PM, Chris Angelico wrote: > I thought it basically functioned top-down. You get a different error > on the print line if there's a "bar = 42" *after* it. This could make > debugging quite confusing. > > Guess it's just one of the consequences of eschewing variable > declarations. Sure it's easier, but there's complications down the > road. It's also a consequence of local variable access being optimized with different bytecode: the type of storage has to be determined at compile time. The compiler could in principle figure out that "bar" cannot be bound at that point and make it a global reference, but it is easy to concoct situations involving loops or conditionals where the storage cannot be determined at compile time, and so the compiler follows the simple rule of making everything local unless it's never assigned. Cheers, Ian