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

有没有办法在 class 之外使用 property?或者类似的东西?

  •  
  •   fy ·
    fy0 · Aug 16, 2014 · 2986 views
    This topic created in 4425 days ago, the information mentioned may be changed or developed.
    我遇到了一个蛋疼的情况:
    文件 a 有单例总控类A,
    由于是总控类,所以 a 会引用其他文件。
    但是其他文件也很有可能引用 a

    于是机智的我打算搞一个文件 b
    在没有任何依赖的情况下去弄 A 的引用,但是强迫症发作,不想让 b 里那个引用看起来是个函数。最好就是和class中的property一样,有什么办法吗?
    2 replies  •  2014-08-16 20:49:15 +08:00
    bcxx
        1
    bcxx  
       Aug 16, 2014
    把 b 做成一个单例,接口都用 property 来写就好了么……
    fy
        2
    fy  
    OP
       Aug 16, 2014
    @bcxx 卧槽 机智啊
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   804 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 22ms · UTC 21:40 · PVG 05:40 · LAX 14:40 · JFK 17:40
    ♥ Do have faith in what you're doing.