Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #6557

Re: scope of function parameters

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <chris@rebertia.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'function,': 0.07; 'foo': 0.09; 'referenced': 0.09; 'subject:parameters': 0.09; 'pm,': 0.10; 'def': 0.12; 'am,': 0.14; 'wrote:': 0.14; 'angelico': 0.16; 'curious,': 0.16; 'namespace.': 0.16; 'namespace?': 0.16; 'subject:function': 0.16; 'traceback': 0.16; '(most': 0.16; "wouldn't": 0.17; 'cc:addr:python-list': 0.17; 'cheers,': 0.19; 'header:In-Reply-To:1': 0.21; 'variable': 0.21; 'cc:2**0': 0.22; 'cc:no real name:2**0': 0.23; 'found,': 0.23; 'last):': 0.23; 'code': 0.24; 'example': 0.27; "i'm": 0.27; 'message- id:@mail.gmail.com': 0.28; 'raise': 0.28; 'cc:addr:python.org': 0.30; 'sun,': 0.30; 'print': 0.31; 'steven': 0.32; "i've": 0.33; 'chris': 0.34; 'file': 0.34; '"",': 0.35; 'assignment': 0.35; "d'aprano": 0.35; 'trigger': 0.35; 'assigned': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.37; 'subject:: ': 0.38; 'received:209': 0.39; '10:47': 0.84; 'now...': 0.84; 'sender:addr:chris': 0.84; 'this...': 0.84; 'local,': 0.91; 'received:209.85.218.46': 0.91; 'received:mail- yi0-f46.google.com': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=rebertia.com; s=google; h=domainkey-signature:mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; bh=ARWDJnzMvY67x1b0vTOYQuCEN83rV/3XPARNOzhskjk=; b=SZun8H4XStW7CsjDnXYpyMPDQaniVRvtZef+ZxUo/sz6rPwO6GatgtmlHQGS7Bew9z 8/jeDO0aCy7/mxgyXW2riE4ofCHDLRA+dMG/ABD1zvHBtrba3GF2aYXzUFx5gdxGZ7AX FVb+z/QLAUD1Thdg2EDNI80Acnn0Te9u6JM/4=
DomainKey-Signature a=rsa-sha1; c=nofws; d=rebertia.com; s=google; h=mime-version:sender:in-reply-to:references:date :x-google-sender-auth:message-id:subject:from:to:cc:content-type; b=VxSo05v6YpoCiYI4oPIOmZmt/H4X7bDlSWq0CM8bDq9phn9klImrROS36SAzymjDxU 8Uljisu1276dQ21AxNvkLuinpCR4CeTBcQprDGEaQqf+8HIguWPG0x8D1lMRb1rLNrph 3u9ctPP8WG0vTYM1H5eWM9SET+oQON8FvlD0I=
MIME-Version 1.0
Sender chris@rebertia.com
In-Reply-To <BANLkTinK=dHCbocURD2+s5uvdonBkS+uFQ@mail.gmail.com>
References <F8395F78-615E-4FBD-B6FC-1D6173EAEA45@mcgill.ca> <mailman.2217.1306662671.9059.python-list@python.org> <4de24045$0$29996$c3e8da3$5496439d@news.astraweb.com> <BANLkTinK=dHCbocURD2+s5uvdonBkS+uFQ@mail.gmail.com>
Date Sun, 29 May 2011 11:01:18 -0700
X-Google-Sender-Auth kDt9rp_sq35h6uOzGfEobopGlr4
Subject Re: scope of function parameters
From Chris Rebert <clp2@rebertia.com>
To Chris Angelico <rosuav@gmail.com>
Content-Type text/plain; charset=UTF-8
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2231.1306692087.9059.python-list@python.org> (permalink)
Lines 27
NNTP-Posting-Host 82.94.164.166
X-Trace 1306692087 news.xs4all.nl 49184 [::ffff:82.94.164.166]:56285
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:6557

Show key headers only | View raw


On Sun, May 29, 2011 at 10:53 AM, Chris Angelico <rosuav@gmail.com> wrote:
> On Sun, May 29, 2011 at 10:47 PM, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> wrote:
>> If a name is assigned to anywhere in the function, treat it as a local,
>> and look it up in the local namespace. If not found, raise
>> UnboundLocalError.
>>
>
> Wait wha? I've never seen this... wouldn't it just create it in the
> local namespace?
>
> Can you give example code that will trigger this error? I'm curious, now...

def foo():
    print bar
    bar = 42

foo()

===>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<stdin>", line 2, in foo
UnboundLocalError: local variable 'bar' referenced before assignment

Cheers,
Chris

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: scope of function parameters Wolfgang Rohdewald <wolfgang@rohdewald.de> - 2011-05-29 11:47 +0200
  Re: scope of function parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 12:47 +0000
    Re: scope of function parameters Chris Angelico <rosuav@gmail.com> - 2011-05-30 03:53 +1000
      Re: scope of function parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 18:28 +0000
    Re: scope of function parameters Chris Rebert <clp2@rebertia.com> - 2011-05-29 11:01 -0700
    Re: scope of function parameters Chris Angelico <rosuav@gmail.com> - 2011-05-30 04:38 +1000
      Re: scope of function parameters Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-29 18:53 +0000
        Re: scope of function parameters Chris Angelico <rosuav@gmail.com> - 2011-05-30 05:20 +1000
    Re: scope of function parameters Ian Kelly <ian.g.kelly@gmail.com> - 2011-05-29 13:12 -0600

csiph-web