前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >The process of attribute lookup in python

The process of attribute lookup in python

作者头像
lesM10
发布2019-08-26 17:02:54
5760
发布2019-08-26 17:02:54
举报
代码语言:javascript
复制
1) If attrname is a special (i.e. Python-provided) attribute for objectname, return it.
(The attribute of Python-provided are something like 'this': 
__lolcat__, __doc__, __weakref__ and so on)

2)Check objectname.__class__.__dict__ for attrname. 
If it exists and is a data-descriptor, return the descriptor result. Search all bases of objectname.__class__ for the same case.

3)Check objectname.__dict__ for attrname, and return if found.
If objectname is a class, search its bases too. 
If it is a class and a descriptor exists in it or its bases, 
return the descriptor result.

4)Check objectname.__class__.__dict__ for attrname. 
If it exists and is a non-data descriptor, return the descriptor result. 
If it exists, and is not a descriptor, just return it. 
(If it exists and is a data descriptor, we shouldn't be here because we would have returned at point 2.) 
Search all bases of objectname.__class__ for same case.

5)Raise AttributeError.

如果objectname实例: 1)Check objectname.__class__.__dict__ for attrname. If it exists and is a data-descriptor, return the descriptor result. Search all bases of objectname.__class__ for the same case. (在父类,以及父类的基类中查找data-descriptor属性,找到data-descriptor才返回) 2)Check objectname.__dict__ for attrname, and return if found. (在实例自身中 查找,只要找到就返回,不管是不是descriptor属性) 3)Check objectname.__class__.__dict__ for attrname. 似乎还要加上objectname.__class__.__basses__.__dict__ If it exists and is a non-data descriptor, return the descriptor result. If it exists, and is not a descriptor, just return it. (If it exists and is a data descriptor, we shouldn't be here because we would have returned at point 2.) (在父类中查找non-data descriptor和非descriptor属性,找到就返回)


如果objectname类对象: 1)Check objectname.__class__.__dict__ for attrname. If it exists and is a data-descriptor, return the descriptor result. Search all bases of objectname.__class__ for the same case. (在父类,以及父类的基类中查找data-descriptor属性,找到data-descriptor才返回) 2)Search objectname.__dict__ and objectname.__bases__ for attrname. If a descriptor exists in objectname or objectname.__bases__, return the descriptor result. (在自身,以及自身的基类中查找descriptor属性,只有找到descriptor属性,才返回) 3)Check objectname.__class__.__dict__ for attrname. 似乎还要加上objectname.__class__.__basses__.__dict__ If it exists and is a non-data descriptor, return the descriptor result. If it exists, and is not a descriptor, just return it. (If it exists and is a data descriptor, we shouldn't be here because we would have returned at point 2.) (在父类中查找non-data descriptor和非descriptor属性,找到就返回)

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.06.27 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档