V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
sudo987
V2EX  ›  Python

关于在__getattribute__调用 getattr()的问题

  •  
  •   sudo987 · 2016-07-05 23:16:33 +08:00 · 2218 次点击
    这是一个创建于 2852 天前的主题,其中的信息可能已经有所发展或是发生改变。
    刚才发了一篇帖子 http://v2ex.com/t/290512#reply1 ,后来想想还是不对, getattr(self.__obj, attr)相当于 self.__obj.attr ,调用的是 self.__obj 本身的__getattribute__方法,跟外层__getattribute__没有关系,不解为什么会出现死循环。
    2 条回复    2016-07-06 13:47:18 +08:00
    perpyy
        1
    perpyy  
       2016-07-06 00:05:53 +08:00
    self.__obj 要不要调外层__getattribute__
    kaneg
        2
    kaneg  
       2016-07-06 13:47:18 +08:00
    覆盖__getattr__而不是__getattribute__。
    代码详情见原帖的回复。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1850 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 16:30 · PVG 00:30 · LAX 09:30 · JFK 12:30
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.