鸭子在 python 中打孔属性
我希望能够添加属性 http://docs.python.org /library/functions.html#property 到一个对象(类的特定实例)。这可能吗?
关于 python 中的鸭子打孔/猴子修补的其他一些问题:
更新:delnan 在评论中回答
I'd like to be able to add a property http://docs.python.org/library/functions.html#property to an object (a specific instance of a class). Is this possible?
Some other questions about duck punching/monkey patching in python:
Adding a Method to an Existing Object Instance
Python: changing methods and attributes at runtime
UPDATE: Answered by delnan in the comments
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以下代码有效:
但我不确定您应该这样做。
Following code works :
But I am not sure you should be doing it.
希望这能解决您的问题。
Hope this solves your problem.