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

Neil Cerutti neilc at norwich.edu
Mon Oct 18 09:24:25 EDT 2010


On 2010-10-18, <fab at slick.airforce-one.org> <fab at slick.airforce-one.org> wrote:
> Hello.
>
> I have a class A that contains two classes B and C:
>
> class A:
>   class B:
>     self.x = 2
>   
>   class C:
>
> Is there a way to access the x  defined in B in class C?

That's not valid Python code. Do you mean:

Class A:
  Class B:
    x = 2

or

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

-- 
Neil Cerutti



More information about the Python-list mailing list