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
fy
V2EX  ›  Python

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

  •  
  •   fy ·
    fy0 · 2014-08-16 14:02:08 +08:00 · 2298 次点击
    这是一个创建于 3556 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我遇到了一个蛋疼的情况:
    文件 a 有单例总控类A,
    由于是总控类,所以 a 会引用其他文件。
    但是其他文件也很有可能引用 a

    于是机智的我打算搞一个文件 b
    在没有任何依赖的情况下去弄 A 的引用,但是强迫症发作,不想让 b 里那个引用看起来是个函数。最好就是和class中的property一样,有什么办法吗?
    2 条回复    2014-08-16 20:49:15 +08:00
    bcxx
        1
    bcxx  
       2014-08-16 14:11:12 +08:00
    把 b 做成一个单例,接口都用 property 来写就好了么……
    fy
        2
    fy  
    OP
       2014-08-16 20:49:15 +08:00
    @bcxx 卧槽 机智啊
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1004 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 22:27 · PVG 06:27 · LAX 15:27 · JFK 18:27
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.