码迷,mamicode.com
首页 > 其他好文 > 详细

对象的另一面

时间:2016-12-29 16:21:11      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:异常   sed   one   and   抛出异常   http   blocks   哈哈   code   

当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)

 

对象的另一面

标签:异常   sed   one   and   抛出异常   http   blocks   哈哈   code   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!