Why can't class variables be used in __init__ keyword arg?
<p>I can't find any documentation on when exactly a class can reference itself. In the following it will fail. This is because the class has been created but not initialized until after <code>__init__</code>'s first line, correct?</p>

<pre><code>class A(object):
    class_var = 'Hi'
    def __init__(self, var=A.class_var):
        self.var = var
</code></pre>

<p>So in the use case where I want to do that is this the best solution:</p>

<pre><code>class A(object):
    class_var = 'Hi'
    def __init__(self, var=None)
        if var is None:
            var = A.class_var
        self.var = var
</code></pre>

<p>Any help or documentation appreciated!</p>

<p>Python scripts are interpreted as you go. So when the interpreter enters <code>__init__()</code> the class variable <code>A</code> isn't defined yet (you are inside it), same with <code>self</code> (that is a different parameter and only available in function body).</p>

<p>However anything in that class is interpreted top to bottom, so <code>class_var</code> is defined so you can simply use that one.</p>

<pre><code>class A(object):
    class_var = 'Hi'
    def __init__(self, var=class_var):
        self.var = var
</code></pre>

<p>but I am not super certain that this will be stable across different interpreters...</p>

python class variables keyword-argument