当前位置:网站首页>PyCharm常用功能 - 断点调试
PyCharm常用功能 - 断点调试
2022-06-27 17:57:00 【我是胖虎啊】
PyCharm - 断点调试
以前写Python程序时, 因为不会断点调试, 所以调试就一直用 print(变量) * N次, debug效率非常低, 经常1个问题得查半天...
后来学了一下Pycharm的断点调试, 发现功能真的很强大, debug的效率提升很多! 所以写篇文章分享下这个技能, 希望大家不再为调试而发愁!
先发下调试代码
import requests
fruit = 'watermelon'
def debug_a():
global fruit
a = 0
for i in range(100):
a += 1
fruit = 'Strawberry'
def debug_b():
c = 20
d = 30
e = 40
debug_a()
debug_c()
print(fruit)
url = "http://httpbin.org/user-agent"
res = requests.get(url)
print(res.json())
b = 0
for j in range(100):
b += 1
def debug_c():
global fruit
fruit = 'lemon'
if __name__ == '__main__':
debug_b()
01
开启调试
当前一共4个断点,.打断点的位置, 见图
设置断点后,点击如图所示的按钮,即可进入调试模式
02
工具栏区
左侧工具栏
上方工具栏
03
基础调试
首先是 变量区介绍
可以先连续点击图中的按钮(快捷键F8), 观察一下variables区域中变量的数据变化情况
连续点击F8, 可以发现 fruit 变量会在运行完debug_c方法后发生变化, c, d, e 变量没变化.
而且, 变量的数据会在每行的后面,使用灰字显示在后面,查看非常方便.这样就完成了初步调试的使用, 是不是很简单!
特别提示: 蓝色条标注的行,例如图中的 debug_a,代表是当前还未运行此行代码, 并即将运行!
04
进阶调试
现在重新调试, 不过不用F8了, 现在按A按钮调试. 运行过程中, 可以发现会进入到debug_a方法内部,此时可以按 C按钮跳出来.同理, 后续也会进入到 debug_c 和 requests 中的内部代码.
再次重新调试, 此时一直按B按钮, 可以发现这次只会进入到 debug_a 和 debug_c方法内部,而不会进入到requests中的内部. 这就是 A按钮 和 B 按钮的区别: 调试过程中, 是否只进入自己定义的方法内部!
现在说下watch区的使用, 首先是打开watch区的按钮, 如图
watch区的界面, 如图所示
watch区的作用: 当 variables 区有很多变量时, 此时可挑选关注的变量到 watch 区
以上就是Pycharm常用的调试技巧,你学会了嘛?
边栏推荐
- SQL Server - Window Function - 解决连续N条记录过滤问题
- Four years of College for an ordinary graduate
- 1027 Colors in Mars
- 拥抱云原生:江苏移动订单中心实践
- 作为软件工程师,给年轻时的自己的建议(下)
- Informatics Orsay all in one 1335: [example 2-4] connected block
- 指针和结构体
- 【登录界面】
- Current market situation and development prospect forecast of the global ductless heating, ventilation and air conditioning system industry in 2022
- What is ICMP? What is the relationship between Ping and ICMP?
猜你喜欢
Error reported by Huada MCU Keil_ Weak's solution
Running lantern experiment based on stm32f103zet6 library function
Jinyuan's high-end IPO was terminated: it was planned to raise 750million Rushan assets and Liyang industrial investment were shareholders
Solution of adding st-link to Huada MCU Keil
Core dynamic Lianke rushes to the scientific innovation board: with an annual revenue of 170million yuan, Beifang Electronics Institute and Zhongcheng venture capital are shareholders
International School of Digital Economics, South China Institute of technology 𞓜 unified Bert for few shot natural language understanding
多伦多大学博士论文 | 深度学习中的训练效率和鲁棒性
openssl客户端编程:一个不起眼的函数导致的SSL会话失败问题
Bit.Store:熊市漫漫,稳定Staking产品或成主旋律
带你认识图数据库性能和场景测试利器LDBC SNB
随机推荐
New Zhongda chongci scientific and Technological Innovation Board: annual revenue of 284million and proposed fund-raising of 557million
429-二叉树(108. 将有序数组转换为二叉搜索树、538. 把二叉搜索树转换为累加树、 106.从中序与后序遍历序列构造二叉树、235. 二叉搜索树的最近公共祖先)
Cdga | what is the core of digital transformation in the transportation industry?
Bit. Store: long bear market, stable stacking products may become the main theme
Buzzer experiment based on stm32f103zet6 library function
maxwell 报错(连接为mysql 8.x)解决方法
Mathematical derivation from perceptron to feedforward neural network
中金证券经理给的开户二维码安全吗?找谁可以开户啊?
数仓的字符截取三胞胎:substrb、substr、substring
Labelimg usage guide
你知道 log4j2 各项配置的全部含义吗?带你了解 log4j2 的全部组件
基于STM32F103ZET6库函数蜂鸣器实验
实战回忆录:从Webshell开始突破边界
一对一关系
通过 G1 GC Log 重新认识 G1 垃圾回收器
Online text batch inversion by line tool
流程判断-三目运算-for循环
华大单片机KEIL报错_WEAK的解决方案
买股票在券商经理的开户链接上开户安全吗?求大神赐教
Photoshop layer related concepts layercomp layers move rotate duplicate layer compound layer