Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!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.022 X-Spam-Evidence: '*H*': 0.96; '*S*': 0.00; 'referenced': 0.09; 'thats': 0.09; 'def': 0.12; 'assignment.': 0.16; 'evaluates': 0.16; 'foo()': 0.16; 'foo():': 0.16; 'jumps': 0.16; 'occurs.': 0.16; 'variable': 0.18; 'bit': 0.19; 'seems': 0.21; 'error': 0.23; 'certainly': 0.24; 'pointer': 0.24; 'message-id:@mail.gmail.com': 0.30; 'explained': 0.31; 'class': 0.32; 'classes': 0.35; 'but': 0.35; 'received:google.com': 0.35; "didn't": 0.36; 'skip:& 10': 0.38; 'thank': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'name': 0.63; 'such': 0.63; 'different': 0.65; 'subject:. ': 0.67 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=/wDJMhLQDwYClWafKj680Rcw7B+ffZcNkv/mCJZs4EA=; b=0ic/Hc3Nxti3RbqqVG/OvW5ijXpeFsF1Q2Q0Q3posZeZPUsQ7NeOQ2HAYDCg4/rjTw zvFieO2FHkb92W84YNTcxMt/nwJtt3La7mF7oCPrGJjpZW91rpqGuf9utdh0cXm3DBq3 MMhiyoC2d7fX6ygsy+LU70we7ZNWuerv5ukr/J8nvWlXsSkcgFzTGeSWFeANpU+FOGUj PIo44z0cSo3G9ry+2O/55srT7xEwSDAuCyF+QVCtO7LYwAOAGqHsUrKr5LBlJYb5v8F8 n5P51GzvuWgkzPiiIlqet2RCvWzkWCV0+CJYQjZHlJ9lTNkmWtdhBRC+oUoeh/1w/G9W hbMA== MIME-Version: 1.0 X-Received: by 10.43.114.8 with SMTP id ey8mr22920124icc.6.1366929473696; Thu, 25 Apr 2013 15:37:53 -0700 (PDT) Date: Thu, 25 Apr 2013 23:37:53 +0100 Subject: Re: baffled classes within a function namespace. Evaluation order. From: Alastair Thompson To: python-list@python.org Content-Type: multipart/alternative; boundary=bcaec5171e1db67a4204db371155 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: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366930490 news.xs4all.nl 15973 [2001:888:2000:d::a6]:44066 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:44370 --bcaec5171e1db67a4204db371155 Content-Type: text/plain; charset=ISO-8859-1 Thats a good pointer to what is going on. Thank you Bas. I am familiar with error such as x=1 def foo(): x = 2 def erm(): print(x) x=3 erm() foo() UnboundLocalError: local variable 'x' referenced before assignment. It seems a bit different for classes (below), as it jumps out to get the value from the global name space, where it didn't for functions (above). x=1 def foo(): x = 2 class erm(): print(x) x = 3 foo() # This evaluates == 1 But you certainly have explained why "NameError: name 'third' is not defined" occurs. --bcaec5171e1db67a4204db371155 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Thats a good pointer to what is going on. T= hank you Bas.

I am familiar with error such as

x=3D1def foo():
=A0 =A0 x =3D 2
=A0 =A0 def erm():
=A0 =A0 =A0 =A0 pri= nt(x)
=A0 =A0 =A0 =A0 x=3D3
=A0 =A0 erm()
foo()=A0
UnboundLocalError: local variable 'x'= referenced before assignment.

It seems a bit different for classes (below), as it jumps out to get the=20 value from the global name space, where it didn't for functions (above)= .

x=3D1
def foo():
=A0 =A0 x =3D 2
=A0 =A0 class erm():
=A0 = =A0 =A0 =A0 print(x)
=A0=A0=A0=A0=A0=A0=A0 x =3D 3
<= div>foo() =A0 =A0=A0 # This evaluates =3D=3D 1=A0

But you cer= tainly have explained why=A0 "NameError: name 'third' is not d= efined" occurs. --bcaec5171e1db67a4204db371155--