Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change variable in Pycharm debugger

Tags:

python

pycharm

When I debug my Python code in Pycharm I often want to change some of the variables that are being set by the original code.
I can do this via the Debugger tab, click on the respective variable and use the Set Value function to change it. This feels too much clicking around and I would prefer to do it via the console interface. But when I try this, it doesn't update the variable:

>>> filename
Out[6]: 'a'
>>> filename='b'
>>> filename
Out[8]: 'a'

Is there a way to change these type of variables via the console interface?

like image 451
Jan-Willem Avatar asked Apr 17 '15 09:04

Jan-Willem


1 Answers

It seems like a bug, the answer above shows that it is possible to manipulate the state of already existing objects, however it seems to be impossible to assign new values (or objects) to the variable itself.

See the following snippet for clarification:

>>> var_obj.temp = 1
>>> var_obj
Out[2]: namespace(temp=1)
>>> var_obj.temp2 = 2
>>> var_obj.temp = 10
>>> var_obj
Out[5]: namespace(temp=10, temp2=2)
>>> var_simple = 10
>>> var_simple
Out[7]: 1

The issue was already reported to the PyCharm issue tracker back in 2013 (see the link). People report that the issue is present since PyCharm 3, some have suggested that it might be a python issue and not PyCharm but its not clear why.

Anyway, the behavior is confusing and should at least be taken into account when trying to debug - until it is fixed.

like image 185
Willy Avatar answered Oct 07 '22 00:10

Willy