How to define class variables using the functions and variables of an instance in Python
<p>Is there a way to define a class variable using the variables and functions of the instance? Thanks</p>

<p>The simplified code looks like this:</p>

<pre><code>def ClassA():
    X = self.func(self.a)

    def __init__(self, avalue):
        self.a = avalue

    def func(self):
        return self.a + 5
</code></pre>

<p>NameError: name 'self' is not defined</p>

<p>Firstly, you define a Class using <code>class</code>, not <code>def</code>.</p>

<p><code>self</code> only needs to be used inside of the class' function definitions, because they change the scope. Outside of them you don't need it:
<code>x = func(a)</code>.</p>

<p>But your code wouldn't work anyways because the instance doesn't exist yet.</p>

python class scope