python基础===猴子补丁

>>> class test:
    def A(self, x, y):
        return x+y

    
>>> t = test()
>>> t.A(10,20)
30
>>> 
>>> def B(self, x, y):
    return x*y

>>> test.A = B
>>> t.A(10,20)
200
>>> 

 

Monkey-patching is the technique of swapping functions or methods with others in order to change a module, library or class behavior.

 

posted @ 2018-07-10 10:14  botoo  阅读(497)  评论(0编辑  收藏  举报