推荐学习书目
› 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
noobsheldon
V2EX  ›  Python

descriptor 类中的__set__和 owner 类中的__setattr__的调用顺序?

  •  
  •   noobsheldon · Jan 22, 2017 via Android · 1894 views
    This topic created in 3582 days ago, the information mentioned may be changed or developed.
    假设有一个 descriptor 类:
    class A(object) :
    def __set__(self, instance, value) :
    print 'set called'
    另有一个类:
    class B(object) :
    x=A()
    def __setattr__(self, name, value) :
    object.__setattr__(self, name, value)
    print self.name
    进行如下操作:
    b=B()
    b.x=6666
    输出: set called
    print self. name 出现错误(print语句在setattr中)
    是为什么啊?各位分析一下,谢谢!
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2680 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 04:21 · PVG 12:21 · LAX 20:21 · JFK 23:21
    ♥ Do have faith in what you're doing.