How to take n steps (iterations) in Python debugger (PyCharm)?(如何在 Python 调试器(PyCharm)中执行 n 步(迭代)?)
问题描述
我的 Python 调试器中有一个断点.我正在使用 PyCharm.我想迭代让我们说 100 次以达到我要调试的点.
I have a breakpoint in my Python debugger. I am using PyCharm. I want to iterate lets say 100 times to reach the point where I want to debug.
现在我可以按 100 次 Resume Program,但是有没有办法只执行一个命令在断点上运行 n 次.
Now I can press 100 x times Resume Program, but is there a way to just execute a command to run n times over the breakpoint.
推荐答案
可以在条件断点中使用函数来计算迭代次数,例如:
You can use a function in a conditional breakpoint to count iterations, take for example:
条件断点可以调用一个函数,该函数除了返回一个布尔值外,还计算循环迭代的次数.
The conditional breakpoint can call a function which in addition to returning a boolean, counts the number of loop iterations.
def your_counter(stop):
global count
count = count + 1
if stop == count:
# count = 0 for periodic break
return True
else:
return False
显示的解决方案适用于单行条件可能不实用和/或 循环计数器需要在外部实现.由于断点条件是程序化的,您可以实现它以定期中断,或根据您想要应用的任何系列/频率标准.
The solution shown is for cases when a one-liner condition might not be practical, and/or when a loop counter needs to be implemented externally. Since the breakpoint condition is programmatic you can implement it to break periodically, or on any series/frequency criteria you want to apply.
在您完成分步调试"后,自定义条件将在您想要的确切迭代处中断.要么按恢复、停止、运行到光标",要么禁用断点右键单击它(实际上这会让你跳出循环).
The custom condition would break at the exact iteration you want, after you're done "step debugging" either press resume, stop, "run to cursor", or disable the breakpoint right-clicking on it (in practice this gets you out of the loop).
您还可以在调试过程中通过在变量监视"中进行编辑来更改任何变量的值.
You can also change the value of any variable in the middle of debugging by editing in "variable watches".
这篇关于如何在 Python 调试器(PyCharm)中执行 n 步(迭代)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Python 调试器(PyCharm)中执行 n 步(迭代)?
基础教程推荐
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 包装空间模型 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01
