Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

python - change variable in Pycharm debugger

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use the magic button

You can totally do that. When stopped at a breakpoint:

  1. In the debugger console tab, click on A "Show Python Prompt"
  2. Type your python code at B to modify the variables at the prompt that shows up
  3. See the results in the console pane at C

Note: The interactive console echoed commands (lines with >>> by C in the image) disappear if you toggle the button off and when the program ends which is kinda weird. I often want to copy the commands I entered.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...