V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Aug 25, 2010 · 6009 views
    This topic created in 5732 days ago, the information mentioned may be changed or developed.
    在静态方法内部如何得知当前静态方法是哪一个类的?
    我在里面试着 dir() 了一下,MS 只有传递进来的参数。

    请高人指点,谢谢。
    5 replies    1970-01-01 08:00:00 +08:00
    billychow
        1
    billychow  
    OP
       Aug 25, 2010
    或许可以用 call stack 实现?
    iwinux
        2
    iwinux  
       Aug 25, 2010
    用 @classmethod ? 不过这样就变成类方法了...
    billychow
        3
    billychow  
    OP
       Aug 25, 2010
    也行,类方法是绑定的,我刚开始可能就问错了。。。
    那么如果是类方法该怎么做呢?
    iwinux
        4
    iwinux  
       Aug 25, 2010
    billychow
        5
    billychow  
    OP
       Aug 25, 2010
    非常感谢!
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3218 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 13:27 · PVG 21:27 · LAX 06:27 · JFK 09:27
    ♥ Do have faith in what you're doing.