GabCaz
GabCaz

Reputation: 119

Evaluating Code at this point in execution with Debug Mode in Pycharm

When stepping through a project in Pycharm in debug mode, we may wish to re-write some sections of the code as we see them. Re-writing them and re-running the entire project up to that point is time-consuming.

Is there a way to open a Jupyter-like, sandbox environment, at any point in the execution, to try writing alternative code snippets and see what their effects are? This would be like opening Jupyter notebooks at this point of the execution, with all the current environment (all objects) available for experimentation. Instead of using the "Evaluate Expression" functionality of Pycharm debugger, this would allow to write and test some code for loops, functions, etc., on the fly, at this place of the execution. The idea is basically to use the "Evaluate Expression" functionality of Pycharm debugger, but to test functions, loops, etc, which "Evaluate Expression" currently does not allow for.

I tried experimenting with code cells in Pycharm pro, but they do not seem to be able to access the environment surrounding the place where they are created.

Upvotes: 0

Views: 793

Answers (1)

BStadlbauer
BStadlbauer

Reputation: 1285

This is possible when using the "Evaluate Expression" functionality in PyCharm already. When you statements in the evaluate expression mode, you have full access to the current interpreter and can run any valid Python code you like.

If you have longer statements I would suggest expanding the expression input field using the expansion arrows: enter image description here

The following shows an actual usage of this: enter image description here

As you can see c is now available in the current interpreter and also printed to the console.

Upvotes: 1

Related Questions