Need help with Python scoping rules

kj no.email at please.post
Fri Aug 28 19:23:37 CEST 2009


In <mailman.596.1251474438.2854.python-list at python.org> Ethan Furman <ethan at stoneleaf.us> writes:

>kj wrote:
>> Miles Kaufmann <milesck at umich.edu> writes:
>>>...because the suite  
>>>namespace and the class namespace would get out of sync when different  
>>>objects were assigned to the class namespace:
>> 
>> 
>>>class C:
>>>  x = 1
>>>  def foo(self):
>>>      print x
>>>      print self.x
>> 
>> 
>>>>>>o = C()
>>>>>>o.foo()
>>>
>>>1
>>>1
>>>
>>>>>>o.x = 2
>>>>>>o.foo()
>>>
>>>1
>>>2
>> 
>> 
>> But this unfortunate situation is already possible, because one
>> can already define
>> 
>> class C:
>>    x = 1
>>    def foo(self):
>>        print C.x
>>        print self.x
>> 
>> which would lead to exactly the same thing.
>> 

>This is not the same thing, and definitely not exactly the same thing. 

Thanks for the clarification!

kynn




More information about the Python-list mailing list