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
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
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
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
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
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
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