简体   繁体   中英

How to watch a variable in pudb?

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

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.

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

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.

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.

Now back to the main window and let your program c ontinue. 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:

asciicast

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM