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


Groups > comp.lang.python > #44370 > unrolled thread

Re: baffled classes within a function namespace. Evaluation order.

Started byAlastair Thompson <hexforge@gmail.com>
First post2013-04-25 23:37 +0100
Last post2013-04-25 23:37 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python


Contents

  Re: baffled classes within a function namespace. Evaluation order. Alastair Thompson <hexforge@gmail.com> - 2013-04-25 23:37 +0100

#44370 — Re: baffled classes within a function namespace. Evaluation order.

FromAlastair Thompson <hexforge@gmail.com>
Date2013-04-25 23:37 +0100
SubjectRe: baffled classes within a function namespace. Evaluation order.
Message-ID<mailman.1072.1366930490.3114.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

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.

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web