python如何卸载模块cmd_使用cmd python模块时,如何使程序正常崩溃?
不幸的是,完成者中的異常被捕獲在readline黑暗深處的某個地方.你可以試試這樣的東西:
import cmd
import traceback
def log_exceptions(fun):
def wrapped(*a, **kw):
try:
return fun(*a, **kw)
except Exception:
print traceback.format_exc()
raise
return wrapped
class App(cmd.Cmd):
@log_exceptions
def complete_foo(self,*arg):
# Uncommenting this line will silently crash the progrm
# making it hard to debug.
# Is there a way to force the program to crash ?
c = 2 + "ddda"
return "d dzpo idz dza dpaoi".split(" ")
$python c.py
(Cmd) foo Traceback (most recent call last):
File "c.py", line 7, in wrapped
return fun(*a, **kw)
File "c.py", line 20, in complete_foo
c = 2 + "ddda"
TypeError: unsupported operand type(s) for +: 'int' and 'str'
在調試完成器之后刪除裝飾器,因為從readline內部打印回溯可能會弄亂您的終端.
不,你不能輕易崩潰readline.
總結
以上是生活随笔為你收集整理的python如何卸载模块cmd_使用cmd python模块时,如何使程序正常崩溃?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql无法打开和锁定权限表_MySQ
- 下一篇: python selenium定位元素方