Classes in a class: how to access variables from one in another

fab at slick.airforce-one.org fab at slick.airforce-one.org
Mon Oct 18 09:45:55 EDT 2010


Neil Cerutti <neilc at norwich.edu> wrote:
>> I have a class A that contains two classes B and C:
>>
>> class A:
>>   class B:
>>     self.x = 2
>>   
>>   class C:

I only wanted to show the structure of the code, not the actual
instructions.

> That's not valid Python code. Do you mean:
> 
> Class A:
>  Class B:
>    x = 2

> Class A:
>  Class B:
>    def __init__(self):
>      self.x = 2
> 

Any of these, aslong as I can access x  in C.

By the way, is the first proposition (that is, x = 2, without the
self.) valid? Is x a global variable then?

Thanks.

-- 
F. Delente



More information about the Python-list mailing list