Python: Call for value inside nested class
<p>I'm trying to call for value from class B that is nested in class A and use it in class C.
I'm getting AttributeError:</p>

<pre><code>class A():
    class B():
        a = 1
    class C():
        b = 2
        c = B.a + b 
AttributeError: class B has no attribute 'a'
</code></pre>

<p>I also tried to call From 'A', Pycharm recognize it, but python still get AttributeError:</p>

<pre><code>class A(object):
    class B(object):
        a = 1
    class C(object):
        b = 2
        c = A.B.a + b 
AttributeError: class A has no attribute 'B'
</code></pre>

<p>Does someone have an idea of how to use it?
Thanks</p>

<p>The problem is that the class template (<code>A</code>) is not constructed while you're calling <code>A.B.a</code>. That is, <code>A</code> is not bound yet to a class.</p>

<p>Try this workaround:</p>

<pre><code>class A():
    class B():
        a = 1
</code></pre>

<p>Now create <code>C</code> separately (<code>A</code> is already defined):</p>

<pre><code>class C():
    b = 2
    c = A.B.a + b
</code></pre>

<p>And reference <code>C</code> from <code>A</code>:</p>

<pre><code>A.C = C
</code></pre>

<p>This can possibly be done via <a class='doc-link' href="http://stackoverflow.com/documentation/python/286/metaclasses#t=201609011200116976592">meta-classes</a>, but could be an over-kill here.</p>

python