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>

<pre><code>class A():
    def __init__(self):
        self.y = 0

    def m(self):
        A.x = 1

b = A()
#print(b.x) doesn't work here since we haven't made it yet. 
b.m() 
print(b.x) #1
c = A()
print(c.x) #1
A.x = 2
print(c.x) #2
print(b.x) #2 
print(vars(A)) #{'__dict__': &lt;attribute '__dict__' of 'A' objects&gt;, '__module__': 'builtins', 'x': 2, '__init__': &lt;function A.__init__ at 0x7f15f800d730&gt;, '__weakref__': &lt;attribute '__weakref__' of 'A' objects&gt;, '__doc__': None, 'm': &lt;function A.m at 0x7f15f800d7b8&gt;}
</code></pre>

<p>Would you be looking for something like this?</p>

python class scope