title: How to "initialize" static variables in python derived classes?
body: <p>Sorry for the bad title, I haven't come up with a better description of my question.</p>
  <p>Let's say I now have a base class A:</p>
  <pre><code>class A():
      def __init__(self, x,y):
          self.x = x
          self.y = y
      
      def add_p(self):
          print(self.p+self.x)
  </code></pre>
  <p>And now class B is the derived class:</p>
  <pre><code>class B(A):
      p = 10 # static variable
      def __init__(self,x,y,z):
          super(B,self).__init__(x,y)
          self.z = z
  </code></pre>
  <p>and now I can do:</p>
  <pre><code>b = B(1,2,3)
  b.add_p() # output 11
  </code></pre>
  <p>But notice that class A <strong>does not</strong> have the member p, so if I do this will get error:</p>
  <pre><code>a = A(1,2)
  A.add_p() # get error
  </code></pre>
  <p>What can I do improve this? Maybe make class A somehow like a virtual class?</p>
  <p>This question is asked because I want to make a base class with all the methods, and make the derived classes. The difference between the base class and the derived class is that the derived class has some &quot;static variables&quot;(like p in the example, but different p in different derived classes). The above example can fit my need, but it seems a little not secure.</p>
  <p>I appreciate any answer or help.</p>