Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'foo': 0.09; 'referenced': 0.09; 'subject:parameters': 0.09; 'def': 0.12; 'am,': 0.14; 'debugging': 0.14; 'received:209.85.214.174': 0.14; 'received :mail-iw0-f174.google.com': 0.14; 'wrote:': 0.14; '*after*': 0.16; 'angelico': 0.16; 'confusing.': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'rebert': 0.16; 'subject:function': 0.16; '\xa0print': 0.16; 'traceback': 0.16; '(most': 0.16; 'mon,': 0.17; 'guess': 0.19; 'header:In-Reply- To:1': 0.21; 'variable': 0.21; 'last):': 0.23; 'message- id:@mail.gmail.com': 0.28; 'received:209.85.214': 0.28; 'it.': 0.31; 'print': 0.31; 'to:addr:python-list': 0.33; 'error': 0.33; 'chris': 0.34; '"",': 0.35; 'assignment': 0.35; 'quite': 0.36; 'received:google.com': 0.37; 'received:209.85': 0.37; 'could': 0.38; 'but': 0.38; 'subject:: ': 0.38; 'received:209': 0.39; 'to:addr:python.org': 0.39; '30,': 0.84; 'functioned': 0.84; 'road.': 0.84; 'wow': 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:date :message-id:subject:from:to:content-type:content-transfer-encoding; bh=bL/sRrNEA5+/1RoGNUJm2F7qMBrDgBmOjGqg848/1SQ=; b=Sm4q5yD2uGZDGLP+othhqHWZ3sZu+/zW+8WMqqmLSPsv9uFxorETYzk2ZoPSXEu5ck j9fLM6Oiuoogurtpk24fVzHSjISqVSIOdVZSk/XWkzolGO/w8E5hrsVMmVjPkBUEHwgD VQ3UzhWzpoYr6dcD809aDnxcEBHAjKb6ioJGg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=Eabc+Dj17zfWtqu17v3aSb1xJYdtiY31uv8gKtnJ/WUyJw8kzVgH09+1qi9mXvjLH6 JTZZexdpsyGlOh1ts1Yb4M9HdeVfULxSw829LUKBvNHTj1sqgo18L0PPvfR6l1c9YPN7 NgrSi1sO/ROOUiKT+iD2bK+TBfwIIndZMvwj8= MIME-Version: 1.0 In-Reply-To: References: <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> Date: Mon, 30 May 2011 04:38:26 +1000 Subject: Re: scope of function parameters From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 24 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1306694309 news.xs4all.nl 49184 [::ffff:82.94.164.166]:33842 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:6561 On Mon, May 30, 2011 at 4:01 AM, Chris Rebert wrote: > def foo(): > =A0 =A0print bar > =A0 =A0bar =3D 42 > > foo() > > =3D=3D=3D> > Traceback (most recent call last): > =A0File "", line 1, in > =A0File "", line 2, in foo > UnboundLocalError: local variable 'bar' referenced before assignment Wow I thought it basically functioned top-down. You get a different error on the print line if there's a "bar =3D 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. Chris Angelico