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

fab at fab at
Mon Oct 18 15:45:55 CEST 2010

Neil Cerutti <neilc at> 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

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


F. Delente

More information about the Python-list mailing list