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>I guess what you tried to do was:</p>

<pre><code>class ClassA():
    def __init__(self,avalue):
        self.a = avalue
        self.X = self.func

    def func(self):
        return self.a + 5

b = ClassA(43)
b.X()
</code></pre>

<p>outputs </p>

<pre><code>48
</code></pre>

python class scope