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

Neil Cerutti neilc at
Mon Oct 18 15:24:25 CEST 2010

On 2010-10-18, <fab at> <fab at> 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


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

Neil Cerutti

More information about the Python-list mailing list