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

如何在静态方法中获得当前调用的上下文?

  •  
  •   billychow ·
    billychow · 2010-08-25 22:01:58 +08:00 · 5232 次点击
    这是一个创建于 4964 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在静态方法内部如何得知当前静态方法是哪一个类的?
    我在里面试着 dir() 了一下,MS 只有传递进来的参数。

    请高人指点,谢谢。
    5 条回复    1970-01-01 08:00:00 +08:00
    billychow
        1
    billychow  
    OP
       2010-08-25 22:04:25 +08:00
    或许可以用 call stack 实现?
    iwinux
        2
    iwinux  
       2010-08-25 22:49:48 +08:00
    用 @classmethod ? 不过这样就变成类方法了...
    billychow
        3
    billychow  
    OP
       2010-08-25 22:53:44 +08:00
    也行,类方法是绑定的,我刚开始可能就问错了。。。
    那么如果是类方法该怎么做呢?
    iwinux
        4
    iwinux  
       2010-08-25 23:03:11 +08:00
    billychow
        5
    billychow  
    OP
       2010-08-25 23:12:03 +08:00
    非常感谢!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3571 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 00:16 · PVG 08:16 · LAX 17:16 · JFK 20:16
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.