如何在pudb中观看变量? [英] How to watch a variable in pudb?

查看:149
本文介绍了如何在pudb中观看变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在调试python脚本,我想监视一个变量,并在变量值更改时得到通知.

I'm debugging a python script, and I want to watch a variable and get notified whenever its value changes.

pudb中有没有办法做到这一点?

Is there a way to do this in pudb?

推荐答案

一旦值发生变化(我知道),您就不能简单地请求通知.

You can't simply ask for notification any time a value changes (that I'm aware of).

但是,您可以设置观察表达式和条件断点,它们应该提供您所需要的功能.

However, you can set both watch expressions and conditional breakpoints which should provide the capability that you're looking for.

首先,转到变量列表( shift + V ),然后转到 N 以添加新手表.输入您要观看的任何变量.

First, go to the variable list (shift+V), then N to add a new watch. Enter in whatever variable you want to watch.

现在在您的值可以更改的位置设置一个断点-返回主窗口,然后找到各行并按 B .然后,让您的程序运行到该行或直到定义了变量.

Now set a breakpoint at the places that your value can change - back to the main window , then find the lines and hit B. Then let your program run to that line or until your variable is defined.

然后 shift + B 选择断点窗口.按 enter 编辑断点.添加一个条件表达式-由于应该立即设置您的值,因此您可以在监视列表中看到该值.一个简单的<variable> != <current value>应该可以.或者,您可以输入特定条件.

Then shift+B to select the breakpoints window. Press enter to edit the breakpoint. Add a conditional expression - since your value should be set by now, you can see the value in your watch list. A simple <variable> != <current value> should do. Or you can enter a specific criteria.

现在返回主窗口,并让程序 c 继续.当该断点的条件为true时,程序将停止运行,并且您将在监视列表中看到该值.

Now back to the main window and let your program continue. When your conditional is true at that breakpoint, your program will stop and you will see the value in your watch list.

例如,请参见以下截屏视频:

For an example, see the following screencast:

这篇关于如何在pudb中观看变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆