Get the full name of a nested class
<p>Given a nested class <code>B</code>:</p>

<pre><code>class A:
    class B:
        def __init__(self):
            pass

ab = A.B()
</code></pre>

<p>How can I get the full name of the class for <code>ab</code>? I'd expect a result like <code>A.B</code>. </p>

<p>You could get the fully qualified name, <a href="https://docs.python.org/3/library/stdtypes.html#definition.__qualname__" rel="nofollow"><code>__qualname__</code></a>, of its <a href="https://docs.python.org/3/library/stdtypes.html#instance.__class__" rel="nofollow"><code>__class__</code></a>:</p>

<pre><code>&gt;&gt;&gt; ab.__class__.__qualname__
'A.B'
</code></pre>

<p>Preferably by using <a href="https://docs.python.org/3/library/functions.html#type" rel="nofollow"><code>type</code></a> (which calls <code>__class__</code> on the instance):</p>

<pre><code>&gt;&gt;&gt; type(ab).__qualname__
</code></pre>

python class python-3.x