Python调试技巧 [英] Python debugging tips

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

问题描述

您调试 Python 的最佳技巧是什么?

请不要只列出一个特定的调试器而没有说明它实际上可以做什么.

相关

解决方案

PDB

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

<预><代码>>>>导入 pdb>>>一个=一个字符串">>>pdb.set_trace()- 返回 -><stdin>(1)<module>()->无(pdb) p a'一个字符串'(Pdb)

要继续执行,请使用 c(或 contcontinue).

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

ipdb 是用于 IPython 的 pdb 版本.它允许将 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天全站免登陆