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

Jean-Michel Pichavant jeanmichel at
Mon Oct 18 16:49:52 CEST 2010

fab at wrote:
> 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
> instructions.

Always post working code, or at least something we can paste in the 
python interpreter (even if it's buggy)

class A:
    class B:
    class C:
        def __init__(self):
            print A.B.x

c = A.C()



More information about the Python-list mailing list