替换实例方法的最佳实践
import types class People: def speak(self): print("hello, world") def speak(self): print("hello, python") p = People() p.speak = types.MethodType(speak, p) p.speak() # hello, python
import types class People: def speak(self): print("hello, world") def speak(self): print("hello, python") p = People() p.speak = types.MethodType(speak, p) p.speak() # hello, python