>>> 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.

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-03
  • 2022-02-18
猜你喜欢
  • 2021-09-12
  • 2021-12-29
  • 2021-10-08
  • 2022-12-23
  • 2022-01-28
相关资源
相似解决方案