Directory: 一、什么是猴子补丁? 二、Monkey Patch功能简介 三、运行时动态改变类的方法 四、总结 五、应用场景 一、什么是猴子补丁? 猴子补丁:Monkey Patch,主要功能就是动态的属性的替换,模块运行时替换的功能。 二、Monkey Patch功能简介 Monkey Patch 允许在运行期间动态修改一个类或模块(注意:python中一切皆对象,包括类、方法、甚至是模块) 三、运行时动态改变类的方法 # 方法一: class A: def func(self): print("Hi") def monkey(self): print("Hi, monkey") a