标签:简单 lis origin 异常 ipython frame developer list 快捷键
import sys
class ExceptionHook:
instance = None
def __call__(self, *args, **kwargs):
if self.instance is None:
from IPython.core import ultratb
self.instance = ultratb.FormattedTB(mode=‘Plain‘,
color_scheme=‘Linux‘, call_pdb=1)
return self.instance(*args, **kwargs)
sys.excepthook = ExceptionHook()
a = 1
b = 0
a / b
? python test.py
Traceback (most recent call last):
File "test.py", line 4, in <module>
a / b
ZeroDivisionError: integer division or modulo by zero
? ipython test.py --pdb
---------------------------------------------------------------------------
ZeroDivisionError Traceback (most recent call last)
/Users/dongweiming/test/test.py in <module>()
2 b = 0
3
----> 4 a / b
ZeroDivisionError: integer division or modulo by zero
*** NameError: name ‘pdb‘ is not defined
> /Users/dongweiming/test/test.py(4)<module>()
1 a = 1
2 b = 0
3
----> 4 a / b
ipdb> p b # p是print的别名
0
ipdb> p a
1
ipdb>
ipdb> help
Documented commands (type help <topic>):
========================================
EOF bt cont enable jump pdef psource run unt
a c continue exit l pdoc q s until
alias cl d h list pfile quit step up
args clear debug help n pinfo r tbreak w
b commands disable ignore next pinfo2 restart u whatis
break condition down j p pp return unalias where
import sys
def get_cur_info():
print sys._getframe().f_code.co_filename # 当前文件名
print sys._getframe(0).f_code.co_name # 当前函数名
print sys._getframe(1).f_code.co_name # 调用该函数的函数的名字,如果没有被调用,则返回module
print sys._getframe().f_lineno # 当前行号
标签:简单 lis origin 异常 ipython frame developer list 快捷键
原文地址:http://www.cnblogs.com/zhizhan/p/6009573.html