But*_*840 5 python ide python-idle
当我使用IDLE运行脚本时,如果脚本遇到异常并且执行停止,那么我将留下一个交互式shell,我可以用它来调查异常时的应用程序状态.这真的很好,但我发现IDLE缺乏编辑器.有没有一种方法可以让我在不使用IDLE的情况下"放弃异常交互式shell"行为?
按如下方式运行您的脚本:
python -m pdb myscript.py
Run Code Online (Sandbox Code Playgroud)
控制台将向您显示:
> /home/user/dir/myscript.py(2)<module>()
Run Code Online (Sandbox Code Playgroud)
-> 第一行(of_my_script)(Pdb)
输入继续
等待事情爆炸:
TypeError: invalid type comparison
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
> /home/user/problemscript.py(567)na_op()
-> raise TypeError("invalid type comparison")
(Pdb)
Run Code Online (Sandbox Code Playgroud)
从现在开始,您基本上就处于MUD中,并且应用了数量惊人的标准命令。
输入where或w查看您在堆栈中的位置:
(Pdb) w
-> return df[df['type']=='dev'][['Dist','Count']].as_matrix()
/home/user/core/ops.py(603)wrapper()
-> res = na_op(values, other)
> /home/user/core/ops.py(567)na_op()
-> raise TypeError("invalid type comparison")
Run Code Online (Sandbox Code Playgroud)
看到那个小>
箭头了吗?这就是我们在堆栈中的位置。
使用list或l环顾四周:
(Pdb) list
564 try:
565 result = getattr(x, name)(y)
566 if result is NotImplemented:
567 >> raise TypeError("invalid type comparison")
568 except (AttributeError):
569 -> result = op(x, y)
570
571 return result
572
573 def wrapper(self, other):
574 if isinstance(other, pd.Series):
Run Code Online (Sandbox Code Playgroud)
要在堆栈中移动,请继续 MUDing 并使用向上( u ) 或向下( d )。
使用args ( a ) 检查当前函数调用时使用的参数:
(Pdb) args
dat = array([], shape=(0, 3), dtype=float64)
dev_classes = {81, 82, 21, 22, 23, 24, 31}
Run Code Online (Sandbox Code Playgroud)
使用p打印变量的内容(或pp进行漂亮打印(或处理角色的基本需求)):
(Pdb) p df
Empty DataFrame
Columns: [Dist, type, Count]
Index: []
Run Code Online (Sandbox Code Playgroud)
使用交互在堆栈中的当前点输入代码。Ctrl+D将带您返回 PDB。
前进吧!需要许多勇敢而强大的冒险家才能击退包围城市的集结的妖精部落。你会成为击败哥布林国王、为种族夺回土地的人吗?
归档时间: |
|
查看次数: |
2152 次 |
最近记录: |