首页 > 其他 > 详细

对象的另一面

时间:2016-12-29 16:17:55      阅读:175      评论:0      收藏:0      [点我收藏+]

当getattr与__getattribute__同时出现时:先找__getattribute__,如果抛出异常则执行getattribute

技术分享
 1 class Foo:
 2     def __init__(self,x):
 3         self.x=x
 4     def __getattr__(self, item):
 5         print("执行的是我")
 6     def __getattribute__(self, item):
 7         print("我是ibute")
 8         raise AttributeError("哈哈")
 9 
10 f1=Foo(10)
11 f1.x
__getattribute__(self, item)

 

对象的另一面

原文:http://www.cnblogs.com/shizhengwen/p/6233128.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!