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

2013-04-26 Thread Steven D'Aprano
On Fri, 26 Apr 2013 09:15:51 +0200, Peter Otten wrote: > Define a global variable x and run it again. I don't have an ancient > Python lying around but my "prediction" is > x = 42 f().x > 42 > > which would be the same behaviour as that of Python 3.3. /facepalm You're absolutely ri

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

2013-04-26 Thread Peter Otten
Steven D'Aprano wrote: > On Fri, 26 Apr 2013 07:39:32 +0200, Peter Otten wrote: > >> A class body is basically a function body that is executed once. To >> allow an assignment >> > x = 42 > class A: >> ... x = x >> ... >> >> which is not possible inside a function > > > As far as

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

2013-04-25 Thread Steven D'Aprano
On Fri, 26 Apr 2013 07:39:32 +0200, Peter Otten wrote: > A class body is basically a function body that is executed once. To > allow an assignment > x = 42 class A: > ... x = x > ... > > which is not possible inside a function As far as I can tell, the documentation says that thi

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

2013-04-25 Thread Peter Otten
Alastair Thompson wrote: > I am completely baffled by the behavior of this code with regards to the > evaluation order of namespaces when assigning the class attributes. Both > classes are nested within a function I called whywhywhy. > > I assumed that example1 and example2 classes would look fi

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

2013-04-25 Thread Alastair Thompson
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 j

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

2013-04-25 Thread Bas
On Thursday, April 25, 2013 11:27:37 PM UTC+2, Alastair Thompson wrote: > I am completely baffled by the behavior of this code with regards to the > evaluation order of namespaces when assigning the class attributes.  Both > classes are nested within a function I called whywhywhy. [snip weird nam

baffled classes within a function namespace. Evaluation order.

2013-04-25 Thread Alastair Thompson
I am completely baffled by the behavior of this code with regards to the evaluation order of namespaces when assigning the class attributes. Both classes are nested within a function I called whywhywhy. I assumed that example1 and example2 classes would look first at their own namespace, then obj