How to debug Python? How to debug python?

little bottle
Release: 2019-05-23 09:26:39
Original
10443 people have browsed it

Debug is a very important debugging skill in coding. By setting breakpoints during the running process, it can help developers better understand the running process. Debugging in Python is not as intuitive as setting breakpoints in the IDE like JAVA or C. Please follow the editor to find out more about it below.

How to debug Python? How to debug python?

There are two ways to debug Python: 1. Run in the command line, 2. Run in the script. Both methods require the use of the pdb module.

Method 1: Run in the command line

$ python -m pdb my_script.py
Copy after login

Method 2: Run in the script

When needed Where the breakpoint is set, insert the method pdb.set_trace()

import pdbdef make_bread():
    pdb.set_trace()    return "I don't have time"print(make_bread())
Copy after login

command: After entering the debugging state, you can enter the command for debugging.

c: (continue)继续执行
w:(words)显示当前行的上下文信息
a:(arguments)打印当前函数的参数列表
s:(stop)执行当前行,并在顶一个可能的时机停止
n:(next)继续执行直到当前函数的下一行或者函数返回值
Copy after login

The above is the detailed content of How to debug Python? How to debug python?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!