Welcome to OGeek Q&A 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...