title: Is there an accepted pythonic way of splitting off a base class part from a subclass object?
body: <p>I am looking for the best way to split off the base class content of a subclass object. That is, if I have an object <code>b</code> of class <code>B</code>, which subclasses class <code>A</code>, I would like a method for class <code>B</code> that returns an object <code>a</code> of class <code>A</code> with the relevant content taken from <code>b</code> (which is a subset of all the content in <code>b</code>). Currently I have roughly the following (the actual classes are more complicated of course, this is a simplified toy example)</p>
  <pre><code>class A:
      def __init__(self):
          self.x = 0
  
      def update(self, dx):
          self.x += dx
  
  class B(A):
      def __init__(self):
          super().__init__()
          self.y = None
  
      def update(self, dx):
          super().update(dx)
          self.y = self.x*self.x
  
      def split_off_base_part(self):
          a = A()
          a.__dict__.update({k: v for k, v in self.__dict__.items() if k in a.__dict__})
          return a
  </code></pre>
  <p>but I am not too happy with it. Is there a more pythonic way of doing this? Possibly one that doesn't require calling <code>A.__init__</code> or is this simply not possible in general?</p>