1

How can one add dynamically a new parent class in python to an existing object?

class A:
    def doA(self): print('A::doA')

class C(A): pass

c = C()

# class 'B' is created after object 'c'
class B:
    def doB(self): print('B::doB')

# XXX: python magic here, which adds dynamically 'B' to the list of parent classes of 'C'
#      as if 'C' was created like this "class C(A,B): pass"

c.doB() # works
S.V
  • 2,149
  • 2
  • 18
  • 41

0 Answers0