5

I have a big dictionary and some of the elements occasionally end up with illegal values. I want to figure out where the illegal values are coming from. PyCharm should constantly monitor the values of my dictionary, and the moment any of them take the illegal value, it should break and let me inspect the state of the program.

I know I can do this by just creating a getter/setter for my dictionary instead of accessing it directly, and then break inside the setter with an appropriate condition.

Is there a way to do it without modifying my code?

Superbest
  • 25,318
  • 14
  • 62
  • 134
  • Does this answer your question? [Stop at the line where a variable gets changed](https://stackoverflow.com/questions/25955204/stop-at-the-line-where-a-variable-gets-changed) – Piotr Dobrogost Apr 07 '20 at 09:59

1 Answers1

8

I'm not sure if this answers your question but you can set a breakpoint on the line of code you want to break at, right click on that break point once it is set and then apply a condition.

An example of such a condition could be:

x > 5

Once you are at the stage in your loop/code where this condition is true i.e. when x = 6 then it will break and you can inspect all the current values/ status of your code.

Hope this helps

dodgerstjw
  • 91
  • 1
  • 6
  • "*Is there a way to do it **without modifying my code**?*" – Superbest Jul 26 '17 at 01:02
  • 1
    you dont need to modify your code, just click on the breakpoint, pycharm will show a menu. – Nithin Mar 10 '19 at 13:14
  • 1
    The problem is there is no line to set a breakpoint on as the OP is not sure where and when the values are being set – *I want to figure out where the illegal values are coming from.* For comparison take a look at the following description of this feature from [documentation](https://sourceware.org/gdb/current/onlinedocs/gdb/Set-Watchpoints.html) of gdb – *You can use a watchpoint to stop execution whenever the value of an expression changes, without having to predict a particular place where this may happen. (This is sometimes called a data breakpoint.)* – Piotr Dobrogost Apr 07 '20 at 09:51