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

被调用函数如何才能知道自己是被哪个函数调用的?

  •  
  •   zyAndroid · 2011-09-10 09:27:53 +08:00 · 5287 次点击
    这是一个创建于 4604 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如A函数和B函数都可能调用C函数来完某个功能
    C函数内部是否有内置的变量记录了调用它的函数的信息,比如函数名什么的?

    求解!
    3 条回复    1970-01-01 08:00:00 +08:00
    lhj2100
        1
    lhj2100  
       2011-09-10 09:33:45 +08:00
    我们这些初学者都是用数组的.
    qiao
        2
    qiao  
       2011-09-10 09:42:08 +08:00
    使用 inspect 模块的 getouterframes 方法。

    文档参见:
    http://docs.python.org/library/inspect.html#inspect.getouterframes
    zyAndroid
        3
    zyAndroid  
    OP
       2011-09-10 09:52:39 +08:00
    @qiao Thanks!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5883 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 02:42 · PVG 10:42 · LAX 19:42 · JFK 22:42
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.