Python调试提示 [英] Python debugging tips

查看:113
本文介绍了Python调试提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



请不要只列出一个特定的调试器,而不用说实际可以做什么。



相关




解决方案

PDB



您可以使用pdb模块,在任何地方插入 pdb.set_trace(),它将用作断点。

 >>> import pdb 
>>>> a =a string
>>>> pdb.set_trace()
--Return -
> < stdin>(1)< module>() - > None
(Pdb)pa
'a string'
(Pdb)

要继续执行,请使用 c (或 cont continue )。



可以使用pdb执行任意的Python表达式。例如,如果发现错误,可以更正代码,然后键入一个类型表达式,以便在运行代码中具有相同的效果。



ipdb是pdb的一个版本 IPython 。它允许使用pdb与所有的IPython功能,包括选项卡完成。



也可以设置pdb自动运行在未捕获的异常。



Pydb 被写为Pdb的增强版本。好处?


What are your best tips for debugging Python?

Please don't just list a particular debugger without saying what it can actually do.

Related

解决方案

PDB

You can use the pdb module, insert pdb.set_trace() anywhere and it will function as a breakpoint.

>>> import pdb
>>> a="a string"
>>> pdb.set_trace()
--Return--
> <stdin>(1)<module>()->None
(Pdb) p a
'a string'
(Pdb)

To continue execution use c (or cont or continue).

It is possible to execute arbitrary Python expressions using pdb. For example, if you find a mistake, you can correct the code, then type a type expression to have the same effect in the running code

ipdb is a version of pdb for IPython. It allows the use of pdb with all the IPython features including tab completion.

It is also possible to set pdb to automatically run on an uncaught exception.

Pydb was written to be an enhanced version of Pdb. Benefits?

这篇关于Python调试提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆