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

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


fab at slick.airforce-one.org wrote:
> 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.
>   
>

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

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

c = A.C()

 >2

JM




More information about the Python-list mailing list