7

Is it possible to "watch" a variable with PyCharm? I want to see the values a variable takes on as it runs through a loop.

Or is there something like console.log()? I am aware of breakpoints (I don't want to break), print and pprint :). It would be awesome to click open a list or object for example.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Christof
  • 3,777
  • 4
  • 37
  • 49
  • But I don't get what's wrong with `print()`ing the value of the variable in the loop? To much work? :) – Christian Dean Nov 18 '16 at 13:37
  • 3
    Well the first drawback is that you have to remember to remove those statements. If you could just right click a var and "watch" it, it wouldn't be necessary. Also, a print statement may work for simple types but lists and dictionaries it's not so great. – Christof Nov 18 '16 at 13:41
  • You can set a breakpoint watch, but not just monitor it live - in many cases, it would be changing too fast for that to be sensible anyway. – jonrsharpe Nov 18 '16 at 13:48
  • 1
    Ideally, the watched value would be logged – Christof Nov 18 '16 at 13:51
  • I wish they would add this feature too. – Rafe Mar 22 '18 at 23:20

1 Answers1

3

Use the "Watches" pane, this shows how to find it: Pycharm - How do I access the "Watches" pane?

screenshot

You can just drag variables from the "Variables" pane into it.

You can also watch expressions, e.g. var + 1.

Breaking when a variable changes however is currently not possible: Stop at the line where a variable gets changed

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • Whilst this may theoretically answer the question, [it would be preferable](//meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Toby Speight Jul 21 '17 at 09:23
  • To the bypassers: Watches option only appears when you click "debug" the program with breakpoints. Simply adding breakpoints and clicking "run" is no use, as I found out after hours of rage – Plutonium smuggler Feb 08 '19 at 22:50