python调试工具

Debugging is an inevitable and often painful process when any programmer developing their programs. However, proper tools could make this process easier and help you to reach your destination faster and with less pain.

当任何程序员开发程序时,调试都是不可避免的过程,并且通常是痛苦的过程。 但是,适当的工具可以使此过程更轻松,并帮助您更快,更轻松地到达目的地。

In this article, we will talk about a lot of python debugging tools that are still being maintained and could help you with your debugging process.

在本文中,我们将讨论仍在维护中的许多 python调试工具,它们可以帮助您进行调试。

打印() (print())

print() is still the number one choice for a lot of python programmers. I won’t spend too much time here because any python programmer should know how to use print() to debug.

对于许多python程序员来说, print()仍然是第一选择。 我在这里不会花费太多时间,因为任何python程序员都应该知道如何使用print()进行调试。

print() has many advantages, it’s built-in, it’s insanely easy to use and it’s very flexible. However, when your project gets larger and more complicated, print() is never good enough to finish the job efficiently.

print()具有许多优点,它是内置的,易于使用并且非常灵活。 但是,当您的项目变得越来越大,越来越复杂时, print()永远不足以有效完成工作。

To solve this problem, we have some “better print” tools.

为了解决这个问题,我们提供了一些“更好的打印”工具。

冰淇淋 (icecream)

icecream is a print tool to basically replace print() function. It’s very intuitive and super easy to use as long as you understand print() debugging. Basically, whenever you want to do print(), you do ic() and most of the time it will do a much better job than print().

icecream是一种打印工具,可以基本上替代print()函数。 只要您了解print()调试,它就非常直观且易于使用。 基本上,每当您要执行print() ,您都会执行ic()并且大多数时候它会比print()做得更好。

For example, it will print out the arguments to the function, the variable name as well as its value. You can do some configurations on icecream to have a different format, but overall it’s a very simple tool that does very simple job. It’s a high-end print and it does provide extra information that we often want.

例如,它将打印出函数的参数,变量名称及其值。 您可以在冰淇淋上进行一些配置以具有不同的格式,但是总的来说,这是一个非常简单的工具,可以完成非常简单的工作。 这是一种高端印刷品,它确实提供了我们经常需要的其他信息。

测井 (logging)

However, sometimes we need auto-formatted print, or we want to control our print under different situations without commenting or deleting the code, or we just need to store the data to a file easily. Python’s built-in logging module is a basic tool to do that.

但是,有时我们需要自动格式化打印,或者我们希望在不同情况下控制打印而无需注释或删除代码,或者我们只需要轻松地将数据存储到文件中即可。 Python的内置日志记录模块是执行此操作的基本工具。

logging should not be strange to python programmers. A very useful feature of logging is to “print” data with a debugging level, which you can adjust globally to control which “print” should be executed. The interface is pretty simple, you can just do logging.info() like print(). The logging module is very extensible so after you are familiar with it, you can config your own format or you own handler.

日志记录对于python程序员应该并不奇怪。 日志记录的一个非常有用的功能是以调试级别“打印”数据,您可以全局调整调试级别以控制应执行的“打印”。 该接口非常简单,您可以像print()一样进行logging.info() print() 。 日志记录模块非常可扩展,因此在您熟悉它之后,就可以配置自己的格式或自己的处理程序。

There are a lot of logging tools that do similar things a logging or enhance logging module itself.

有许多日志记录工具可以执行类似日志记录的功能或增强日志记录模块本身的功能。

Loguru (loguru)

loguru is a built-from-scratch logging package. It has an easier-to-use interface compared to logging module. You can specify handler, formatter and filter using one unified function. You can also rotate the logging file when it’s getting too large or at a specific time.

loguru是从头开始构建的日志记录软件包。 与日志记录模块相比,它具有易于使用的界面。 您可以使用一个统一的函数来指定处理程序,格式化程序和过滤器。 当日志文件太大或在特定时间时,您还可以旋转日志文件。

loguru also supports colored logging, multi-thread and multi-process, as well as exception handling.

loguru还支持彩色日志记录,多线程和多进程以及异常处理。

Overall, loguru has a very simple and straight forward out-of-the-box interface for beginner users, and many advanced features if you want more. This is a standard for a good package: easy when you start, powerful when you master.

总体而言,loguru为初学者提供了一个非常简单直接的开箱即用的界面,如果需要更多的功能,还提供了许多高级功能。 这是一个好的软件包的标准:启动时很容易,掌握时就很强大。

结构日志 (structlog)

Compared to loguru, structlog focuses more on the data structure of the log. The purpose is to keep log as a data structure with enough flexibility.

与loguru相比,structlog 更加关注日志的数据结构。 目的是使日志作为具有足够灵活性的数据结构。

structlog also supports “processing” the log by multiple pipelines which do their own job, like getting the timestamp or inserting the stack info. Those are all benefits from keeping logs as data structures.

structlog还支持通过多个流水线“处理”日志,这些流水线可以完成自己的工作,例如获取时间戳或插入堆栈信息。 这些都是将日志保留为数据结构的好处。

If you need a flexible logging tool for your module, maybe take a look at structlog.

如果您的模块需要灵活的日志记录工具,则可以看一下structlog。

色彩日志 (colorlog)

colorlog is more like an extension to the existing logging module. Basically by adding the implemented formatter and handler to built-in logging module, you can log with color.

colorlog更像是现有日志模块的扩展。 基本上,通过将实现的格式化程序和处理程序添加到内置的日志记录模块中,可以使用颜色进行日志记录。

coloredlog is another package that does similar stuff but with a simpler interface. They are both easy upgrades to what you might be already familiar with.

colouredlog是另一个具有类似功能但界面更简单的软件包。 它们都是您可能已经熟悉的简单升级。

皮诺 (PySnooper)

Programmers often realize that simple print and logging is not enough. They need to know more about the details and they don’t want to add so many lines of print/logging functions. And that’s where snoop helps.

程序员经常意识到,简单的打印和记录是不够的。 他们需要更多地了解细节,并且不想添加太多行的打印/记录功能。 这就是snoop的帮助。

PySnooper is a very popular tool to trace code. It will instrument a function by a decorator like and then print every line that’s executed and the corresponding variables.

PySnooper是一种非常流行的跟踪代码的工具。 它将通过装饰器来检测一个函数,然后打印执行的每一行以及相应的变量。

You can simply “snoop” a function by adding a decorator @pysnooper.snoop() to it. You can also make it recursive and specify the depth you want to go in. PySnooper is very helpful when you really want to know how a specific function is executed.

您可以通过@pysnooper.snoop()添加装饰器@pysnooper.snoop()来简单地“监听”一个函数。 您也可以使其递归并指定要进入的深度。当您确实想知道特定功能的执行方式时,PySnooper会非常有用。

There’s another project based on PySnooper called snoop, which combined PySnooper and some other debugging tools as a tool-box.

还有一个基于PySnooper的项目,称为snoop ,它将PySnooper和其他一些调试工具组合为工具箱。

猎人 (hunter)

hunter is another tracing tool that provides similar information as PySnooper. However, it has a more advanced interface and more powerful features.

hunter是另一个提供与PySnooper类似信息的跟踪工具。 但是,它具有更高级的界面和更强大的功能。

First of all, instead of adding decorators to all the functions you are interested in, hunter enabled it’s tracer once and let the user specify a query function to determine whether a line/function should be traced and printed. It’s a more complicated setup, but definitely more flexible and powerful.

首先,不是将装饰器添加到您感兴趣的所有功能中,而是启用了hunter一次它的跟踪器,并让用户指定查询函数以确定是否应跟踪和打印行/函数。 这是一个更复杂的设置,但绝对更加灵活和强大。

hunter also has a cython option which should reduce overhead compared to pure python implementation.

hunter还有一个cython选项,与纯python实现相比,它可以减少开销。

pdb (pdb)

There are always times, when logging is not good enough. They might be too slow to provide enough information. That’s when you need a real debugger. A debugger is very powerful, but has a rather steep learning curve.

有时候,日志记录不够好。 它们可能太慢而无法提供足够的信息。 那就是您需要真正的调试器的时候。 调试器功能非常强大,但学习曲线却比较陡峭。

pdb is the built-in debugger in python. You can single step or step over using the debugger, examining how the program runs. You can check any variable any time and even changing the variable when you code is executing.

pdb是python中的内置调试器。 您可以使用调试器来单步执行,也可以单步执行,以检查程序的运行方式。 您可以随时检查任何变量,甚至可以在执行代码时更改变量。

pdb is not that hard to use but it is definitely a tool that many developers want to avoid. The command line interface is not that intuitive and you need to memorize some commands.

pdb并不难使用,但它绝对是许多开发人员想要避免使用的工具。 命令行界面不是那么直观,您需要记住一些命令。

There are enhanced versions of pdb like pdb++ and ipdb. They all have similar interface as pdb and more features, normally a better formatted output. If you already know how pdb works, you may enjoy more features using those packages.

有pdb的增强版本,例如pdb ++和ipdb 。 它们都具有与pdb类似的界面,并且具有更多功能,通常具有更好的格式化输出。 如果您已经知道pdb的工作方式,则可以使用这些软件包享受更多功能。

GUI调试器 (GUI debuggers)

Any command line interface is always one dimensional, and we are wasting the 2-d nature of our monitor. So graphic debuggers are much more intuitive to us.

任何命令行界面始终都是一维的,我们浪费了显示器的二维性质。 因此,图形调试器对我们而言更加直观。

There are many GUI debuggers in the market. VSCode, PyCharm, BirdsEye. I won’t name them all, but as long as you really need a debugger for your large project, you will get familiarized with them.

市场上有许多GUI调试器。 VSCode,PyCharm,BirdsEye。 我不会全部命名,但是只要您确实需要大型项目的调试器,您就会熟悉它们。

VizTracer (VizTracer)

(spoil alert, I built this tool)

(破坏警报,我构建了此工具)

What about a graphical logging tool with a debugger that requires minimum setup?

带有调试器且需要最少设置的图形记录工具又如何呢?

Every tool has its pros and cons. As for debugging tools, we always need to balance between detailedness and readability, instrumentation and overhead, powerful features and accessibility. VizTracer is trying to balance everything to a point where no existing tool is solving the area.

每个工具都有其优点和缺点。 对于调试工具,我们始终需要在详细性和可读性,工具和开销,强大的功能和可访问性之间取得平衡。 VizTracer试图平衡所有内容,以至没有现有工具可以解决该问题。

VizTracer’s most basic functionality is to record all the function entries/exits and generate a report in stand-alone HTML file that can be open with Chrome.

VizTracer的最基本功能是记录所有功能条目/退出并以独立HTML文件生成报告,该文件可通过Chrome打开。

It records every function entry/exit so the information is very detailed(of course not line-level), and it shows it with chrome-powered trace viewer which gives a much better readability compared to string logs. However, if you do need some data inside the function, you can use the custom events to log arbitrary data and they’ll be displayed on the graphic report.

它记录了每个函数的进入/退出,因此信息非常详细(当然不是行级别的),并且使用基于chrome的跟踪查看器进行显示,与字符串日志相比,可读性更好。 但是,如果函数中确实需要一些数据,则可以使用自定义事件记录任意数据,并将它们显示在图形报告中。

VizTracer instrumented only function entry/exit and is using C extension instead of python code. The overhead is about the same as cProfile, which is much better than any line-level tracing tools. If you need even better overhead, VizTracer also provides many filters to filter out the functions you are not interested in.

VizTracer仅检测功能入口/出口,并且正在使用C扩展而不是python代码。 开销与cProfile大致相同,这比任何行级跟踪工具都要好得多。 如果您需要更好的开销,则VizTracer还提供许多过滤器以过滤掉您不感兴趣的功能。

For the basic usage, you don’t need to change your source code at all. Every thing is as simple as viztracer your_script.py and you will have your detailed logging report. Even for a lot of advanced features, you can still do it on command line interface without having to intruding your source code.

对于基本用法,您根本不需要更改源代码。 每件事都像viztracer your_script.py一样简单,您将获得详细的日志记录报告。 即使具有许多高级功能,您仍然可以在命令行界面上进行操作而不必侵入您的源代码。

VizTracer also has a virtual debugger, which you can use to debug the json “report” you generated by vdb your_report.json. You can use it as pdb to examine how your code was executed. Because VizTracer has all the information, you can even step back in time! You are a time traveler in vdb(VizTracer Debugger).

VizTracer还具有一个虚拟调试器,可用于调试由vdb your_report.json生成的json“报告”。 您可以将其用作pdb来检查代码的执行方式。 因为VizTracer具有所有信息,所以您甚至可以倒退! 您是vdb(VizTracer Debugger)中的时间旅行者。

Sorry for the promotion of my own tool, but I do think it’s really cool and should be shared with people :)

很抱歉推广我自己的工具,但我确实认为它真的很酷,应该与人们分享:)

However, even if you don’t enjoy the VizTracer part, hopefully the other cool debugging tools I introduced would be help for you and your python program!

但是,即使您不喜欢VizTracer部分,也希望我介绍的其他出色的调试工具对您和您的python程序有所帮​​助!

翻译自: https://medium.com/@tiangao_37980/all-python-debugging-tools-you-need-to-know-in-2020-e3ff66b8f318

python调试工具


http://www.taodudu.cc/news/show-3336470.html

相关文章:

  • mobx基础学习
  • PyQt5学习Ⅱ(菜单,工具栏和布局管理)
  • 学习笔记(1):用友U8视频教程全集(全模块)-薪资管理
  • 学习笔记(01):用友U8视频教程全集(全模块)-存货核算流程*
  • 最新用友U8V15.0全产品培训视频教程合集
  • 视频教程-微博登录接口开发-PHP
  • 视频教程-requirejs新手上手课-JavaScript
  • 用友U8.0 V10虚拟机安装教VBox + Vmware
  • 视频教程-laravel5.6 初级入门-PHP
  • 视频教程-Layer 弹窗入门-jQuery
  • 视频教程-Markdown 标记语言-PHP
  • 用友U8视频教程全集(系统管理)-金速鹏-专题视频课程
  • 用友U8视频教程全集(销售管理)-金速鹏-专题视频课程
  • 视频教程-用友U8视频教程全集(采购管理)-ERP
  • 用友U8视频教程全集(库存管理)-金速鹏-专题视频课程
  • 用友U8视频教程全集(采购管理)-金速鹏-专题视频课程
  • 视频教程-用友U8视频教程全集(系统管理)-ERP
  • 视频教程-用友U8视频教程全集(库存管理)-ERP
  • 用友ERP U8软件安装
  • 视频教程-用友U8视频教程全集(全模块)-ERP
  • 用友U8视频教程全集(全模块)-金速鹏-专题视频课程
  • 如何用视频剪辑软件Vegas剪视频
  • 视频剪辑软件分析
  • 图片尺寸太大?教你用简单的方法轻松修改图片大小
  • matlab怎么改plot字体大小,Matlab 修改plot大小
  • vue设置img大小的属性_vue-quill-editor图片大小修改
  • 云计算提供商锁定的影响以及解决方案
  • [心得]麦肯锡7步法解决问题实际应用
  • 跨域问题及解决方式(CORS)
  • AppScan安全问题解决方案

python调试工具_您需要在2020年了解的所有python调试工具相关推荐

  1. 如何在mac终端运行python程序_如何在mac上的终端上运行python?

    First, the lesson said to simply type, python, into terminal to start coding in python (I don't know ...

  2. 转行学python后悔_月薪13k的我为什么要转行学Python?

    在职业规划包括人生方向上,选择很重要. 一句很经典的话做总结"方向不对,努力白费". 选择自己感兴趣的工作,全力以赴投入其中,"唯有爱的深,才能做的好" 当你付 ...

  3. java执行python脚本_使用Runtime.getRuntime().exec()在java中调用python脚本

    举例有一个Python脚本叫test.py,现在想要在Java里调用这个脚本.假定这个test.py里面使用了拓展的包,使得pythoninterpreter之类内嵌的编译器无法使用,那么只能采用ja ...

  4. excel python插件_再见 VBA!神器工具统一 Excel 和 Python

    大家好,我是东哥. 经常给大家推荐好用的数据分析工具,也收到了铁子们的各种好评.这次也不例外,我要再推荐一个,而且是个爆款神器. Excel和Jupyter Notebok都是我每天必用的工具,而且两 ...

  5. python速度_只需一行代码,让你的Python运算速度更加流畅!

    python一直被病垢运行速度太慢,但是实际上python的执行效率并不慢,慢的是python用的解释器Cpython运行效率太差. "一行代码让python的运行速度提高100倍" ...

  6. 不会数学可以学python吗_数学和英语都很差,学习Python难吗?看完我相信你会坚定你的选择...

    前言 首先!我想说:python 不需要很高的数学水平,英语也是很初级就可以入门,因为它的语法很简单,若你的英语不是很好,可以看很多中文的书,比如python基础教程,廖雪峰的python教程,或者看 ...

  7. python 归一化_几种归一化方法(Normalization Method)python实现

    数据归一化问题是数据挖掘中特征向量表达时的重要问题,当不同的特征成列在一起的时候,由于特征本身表达方式的原因而导致在绝对数值上的小数据被大数据"吃掉"的情况,这个时候我们需要做的就 ...

  8. 教你如何用python表白_情人节来了,教你个用 Python 表白的技巧

    作者:@明哥 公众号:Python编程时光 2020年,这个看起来如此浪漫的年份,你还是一个人吗?难不成我还能是一条狗? 18年的时候,写过一篇介绍如何使用 Python 来表白的文章. 虽然创意和使 ...

  9. python 降噪_使用降噪自动编码器重建损坏的数据(Python代码)

    python 降噪 Autoencoders aren't too useful in practice, but they can be used to denoise images quite s ...

最新文章

  1. mysql优化篇_MySQL优化篇-查询优化
  2. 修改httpd默认端口号
  3. 金融专业计算机大几可以不学,大学选专业,只要明白4个档次,3个原则,基本不会有太大的问题...
  4. 跨域调用WebService
  5. UI设计素材|切换动效,打破界面沉闷感
  6. 【分享】免费建立自己的站点
  7. ThinkPHP5 ajax传值到后台进行处理(验证是否含有某段字符串、截取字符串、字符串转数组)...
  8. ECharts之force力导向布局图——数据源说明及后端API约定
  9. 拓端tecdat|R语言实现LASSO回归——自己编写LASSO回归算法
  10. pxe安装linux系统工具,Linux的PXE自动化无人值守安装系统
  11. 计算机黑屏的原因及修复,导致笔记本电脑开机黑屏的原因以及对应的修复方法...
  12. win10隐藏网络计算机,连接隐藏网络,教你win10系统电脑连接隐藏网络的方法
  13. 回首150年炒股史 | 消灭散户的终极武器竟然是“它”?!
  14. 基于Python的招聘信息可视化分析研究
  15. 内网计算机安全使用规则,局域网网络安全注意事项
  16. Java IDEA的使用
  17. swarm-XDai主网免bzz质押和rpc全套搭建教程-windows
  18. 40+倍提升,详解 JuiceFS 元数据备份恢复性能优化之路
  19. nacos Field ‘nid‘ doesn‘t have a default value;
  20. julia的plot

热门文章

  1. (判断素数)及方法的定义及应用
  2. (四)谷歌地图使用,英文说明书翻译
  3. solrcloud java_SolrCloud的介绍
  4. 企业绩效考核的有效性研究
  5. C4DS22下载 Cinema4D S22下载安装教程
  6. 如何看电脑PHP版本,电脑怎么看系统版本(怎么看电脑系统的版本?)
  7. Highcharts高级响应能力支持
  8. MySQL的几种常用存储引擎
  9. Linux权限位中的s、t
  10. 中国真空泵制造行业需求状况及盈利前景预测报告(2022-2027年)