In Python can one implement mixin behavior without using inheritance?

前端 未结 8 1500
醉梦人生
醉梦人生 2021-02-06 13:10

Is there a reasonable way in Python to implement mixin behavior similar to that found in Ruby -- that is, without using inheritance?

class Mixin(object):
    def         


        
8条回答
  •  不知归路
    2021-02-06 13:39

    You can add the methods as functions:

    Foo.b = Mixin.b.im_func
    Foo.c = Mixin.c.im_func
    

提交回复
热议问题