你可以使用其他两种不同的技术来修改类: 猴子补丁(monkey patching) 类装饰器(class decorators) 99% 你需要修改类的时候,你最好使用这两种技术。 但是 99% 的这种时候,你其实根本就不需要修改类 :-)。
基于13个网页-相关网页
A clean, and non-ugly, solution to the above need might be to add class decorators to Python.
上述问题的一种干净、漂亮的解决方案可能需要向 Python 添加类装饰器。
Decorators do not currently let you modify class instantiation per se, but they can massage the methods that are attached to the class.
decorator目前并不允许您修改类实例化本身,但是它们可以修改依附于类的方法。
应用推荐