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

一个有关 Python , metaclass 的问题。详细看 gist

  •  
  •   baocaixiong · Aug 14, 2014 · 3160 views
    This topic created in 4460 days ago, the information mentioned may be changed or developed.


    我这里是想实现在 import 包的时候将 class 中的用户定义的属性保存在 class 中的`__standards__`属性中,供后面调用
    3 replies  •  2014-08-14 15:26:57 +08:00
    timonwong
        1
    timonwong  
       Aug 14, 2014   ❤️ 1
    原因很简单,要知道 dict() 是mutiple 的,而且你给了它一个 instance:
    {_STANDARDS: dict()}
    baocaixiong
        2
    baocaixiong  
    OP
       Aug 14, 2014
    已经弄明白了。

    33 行 StdData = _StdData('StdData', (StdData,), {_STANDARDS: dict()})
    dict() 这里始终是同一个dict()
    baocaixiong
        3
    baocaixiong  
    OP
       Aug 14, 2014
    @timonwong 感谢。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2576 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 12:09 · PVG 20:09 · LAX 05:09 · JFK 08:09
    ♥ Do have faith in what you're doing.