python - 代码调试的好帮手sys._getframe()

python 的调试,令人非常忧伤,通过将输出路径打印的方式,可以提高很大的方便性:

import sys
#coding=utf-8
def get_cur_info():
       print sys._getframe().f_code.co_filename  #当前文件名,可以通过__file__获得
       print sys._getframe().f_code.co_name  #当前函数名
       print sys._getframe().f_lineno #当前行号

       return "{\"info\":\"print info\":\"%s\"}" % (sys._getframe().f_code.co_filename)
       return "{\"info\":\"print info\":\"%s\"}" % (sys._getframe().f_code.co_name)
       return "{\"info\":\"print info(%d)\"}" % (sys._getframe().f_lineno)

  

posted @ 2016-03-31 18:29  blitheG  阅读(1550)  评论(0编辑  收藏  举报