Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the debugging skills of python

Shulou Source: shulou.com Published: 2022-06-01 05:29:25 10月21日 Update

This article will explain in detail what python debugging skills are, and the editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

Debugging skills

1. Script debugging

Script debugging for Python can be done using the pdb module. It allows us to set breakpoints at will in the script:

Import pdb pdb.set_trace ()

You can specify pdb.set_trace () and set breakpoints anywhere in the script, which is very convenient

two。 Debug programs in shell

In shell, you can start an interactive environment by using the-I option of python, where you can print run-time variable values and call functions, such as the following test.py script

Def func (): return 0 / 0 func ()

Run the script through python-I test.py in shell

We import pdb and then call pdb.pm () to start the debugger

It will show the place where the program crashes, where we exit the program and set a breakpoint:

Import pdb; def func (): pdb.set_trace () return 0 / 0 func ()

Run it again, it will stop at the breakpoint, step to the next step

In this way, we can debug and trace the execution of the program. By setting a breakpoint, and then when you run the program, execution stops at the breakpoint, and you can check the program, such as listing function parameters, evaluating expressions, listing variables, or step stepping.

This is the end of this article on "what are the python debugging skills?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Breakpoints programs scripts runs techniques articles functions more environment good convenient practical interactive location content again parameters variables places articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei vpn macOS MariaDB Redmi