0

This is about Pycharm 4.5.1.

Whenever I stop at a breakpoint in a function I cannot overwrite or create any variables defined in the function in the interactive python console (regardless of whether these function variables are defined before or after the breakpoint).

By contrast, when my debugging point is not within a function, I can overwrite any variables defined within the current script. Is that a bug or intended behavior? Anyway it drives me crazy, because it makes any interactive break-point-guided developing almost impossible.

My question: Is there any way to get around this annoying behavior in Pycharm?

MINIMAL EXAMPLES

>>> refers to my input at the interactive debugging console, once I reached the indicated breakpoint.

This works:

a = 3  # <- put breakpoint here

>>> a = 4

>>> a

Out[7]: 4

This works:

def test():
    a = 3  # <- put breakpoint here
test()

>>> b = 4

>>> b

Out[7]: 4

This does not work:

def test():    
    a = 3  # <- put breakpoint here
test()

>>> a = 4

>>> a

Traceback (most recent call last):

File "/redacted/local/lib/python2.7/site-packages/IPython/core/interactiveshell.py", line 3035, in run_code exec(code_obj, self.user_global_ns, self.user_ns)

File "< ipython-input-5-5cd59f58ac08>", line 1, in < module>

a

NameError: name 'a' is not defined

This does not work:

def test():
    a = 3
    print('just for the sake of placing a breakpoint')  # <- put breakpoint here
test()

>>> a = 4

>>> a

Out[7]: 3

monade
  • 303
  • 1
  • 10

1 Answers1

0

What I do is from the Debugger execute Alt + F8 or Evaluate Expression

  1. Create your function and insert breaking point after declaring the variable enter image description here
  2. Bring up the Evaluate Expression dialog and reassign a. Note the difference enter image description here
  3. Close and resume the program and notice output in console enter image description here
Leb
  • 15,483
  • 10
  • 56
  • 75
  • Thanks, that would work as a work-around! Still it's a bit cumbersome this way. It would be so much easier if one could reassign variables in the supposedly "interactive" console. – monade Oct 12 '15 at 12:14
  • I'm personally not a fan of their overall debugging setup. – Leb Oct 12 '15 at 12:16
  • Yeah, me neither. Are you aware of any IDE with comparable functionality (\*), but better, possibly Matlab-like debugging functionality? (\*) well I know, that's very vague - but code introspection at a similar level as Pycharm would be a start. – monade Oct 12 '15 at 14:30
  • I just encountered the "**quick** evaluate expression" option (Ctrl + Alt + 8) which avoids opening a separate dialog window. It works by selecting the current command in the console (or in the editor) and pressing Ctrl + Alt + 8. Far from ideal, but at least workable -> accepted answer. – monade Oct 12 '15 at 16:51