zoukankan      html  css  js  c++  java
  • Python stack

    用 sys._getframe() 函数获取调用堆栈帧信息

    #!/usr/bin/env python
    # -*- coding: utf-8 -*-

    import sys

    def test(depth = 0):
    frame = sys._getframe(depth)
    code = frame.f_code

    print "frame depth = ", depth
    print "func name = ", code.co_name
    print "func filename = ", code.co_filename
    print "func lineno = ", code.co_firstlineno
    print "func locals = ", frame.f_locals

    def main():
    test(0)
    print "--------"
    test(1)

    if __name__ == "__main__":
    main()

    输出:
    frame depth = 0
    func name = test
    func filename = D:\...\main.py
    func lineno = 6
    func locals = {'frame': <frame object at 0x01209880>, 'code': <code object test at 011EBF98, file "D:\...\main.py", line 6>, 'depth': 0}
    --------
    frame depth = 1
    func name = main
    func filename = D:\...\main.py
    func lineno = 16
    func locals = {}

    重点链接

    http://docs.python.org/library/inspect.html#inspect-stack
    http://hg.python.org/cpython/file/2.7/Lib/inspect.py
    http://blog.csdn.net/program_think/article/details/7240881
    http://www.okpython.com/thread-2429-1-1.html
    http://code.activestate.com/lists/python-list/361744/
    http://hi.baidu.com/limodou/blog/item/83f4b21937ed174043a9adb5.html Python的动态性
    http://autumn-sea.appspot.com/page/agphdXR1bW4tc2Vhcg0LEgRCbG9nGNGcgQEM
    http://nedbatchelder.com/blog/200804/the_structure_of_pyc_files.html Pyc解密

  • 相关阅读:
    vsphere中虚机的cpu热插拔和内存热添加
    vsphere storage appliance工作原理和实施
    vmware产品框架-计算中心,5.1更新等
    vcenter建立cluster
    vcenter 5.1安装亲历
    openfiler在esxi下的安装配置
    升级华为s2016
    ubuntu下配置华为交换机s2016
    Fibre Channel address weaknesses
    vsphere HA内幕变化
  • 原文地址:https://www.cnblogs.com/moonflow/p/2388305.html
Copyright © 2011-2022 走看看