Adding base class to existing object in python

后端 未结 3 1731
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-11 22:28

I have several objects of different kinds (different function names, different signatures) and I monkey patch them to have a common way to access them from different functio

3条回答
  •  半阙折子戏
    2021-01-11 23:05

    Based on a comment on another answer, this is another way to patch the base class:

    class Patched(instance.__class__, ExtraBase):
        pass
    
    instance.__class__ = Patched
    

提交回复
热议问题