I'm having trouble understanding scope of a variable in a subclass

Gabriel Genellina gagsl-py at yahoo.com.ar
Thu Dec 28 03:49:46 EST 2006


At Thursday 28/12/2006 01:39, Pyenos wrote:

>class Class1:
>         class Class2(Class1):
>                 variable="variable"
>                 class Class3(Class2):
>                         print Class1().Class2().variable #problem
>
>Also, why is this wrong?

Again, don't write just "problem"!
What do you want do do? Writing random statements at random order and 
random indentation levels is not the best way to learn Python (nor anything!)

Defining a nested class which itself inherits from its container 
*might* make *some* sense in very specific circunstances, but 
certainly is *not* a recommended newbie practice.
It's like using the accelerator and brake at the same time when 
driving - an experienced driver *might* do that in certain 
circunstances, but if you are learning to drive, you either 
accelerate or either use the brake but NOT both.


-- 
Gabriel Genellina
Softlab SRL 


	

	
		
__________________________________________________ 
Preguntá. Respondé. Descubrí. 
Todo lo que querías saber, y lo que ni imaginabas, 
está en Yahoo! Respuestas (Beta). 
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas 




More information about the Python-list mailing list