开发者

Override all operators in python

开发者 https://www.devze.com 2022-12-18 20:33 出处:网络
I have a wrapper class for an object. I want it to apply all operations applied to it on the wrapped object, e.g wrapper+=a would yield the same result as wrapped+=a, for instance. I want to apply thi

I have a wrapper class for an object. I want it to apply all operations applied to it on the wrapped object, e.g wrapper+=a would yield the same result as wrapped+=a, for instance. I want to apply this for al开发者_如何转开发l operators. Any simple way to override all operators without overriding each one explicitly?


ActiveState Code: Recipe 496741: Object Proxying


No, sorry. Though you could write an interface (probably as a decorator or base class) that makes this easy, if you need to do it more than once. Or use one provided already. (Guess I was 40s too late.)

0

精彩评论

暂无评论...
验证码 换一张
取 消