I am new to PyCharm. I have been using IDLE for a long time.
It is very convenient to use Python objects after script execution in IDLE. Is there any way to use scr
A further alternative is to simply use the same command that Spyder uses to "interactively" run a script:
>>> runfile('myscript.py')
Then you can open the variable explorer for the interactive console and rerun the script by running the above command again. Very similar to the Spyder workflow. All the other above methods will leave you with an interactive console prompt but not the option to open a variable explorer so if you are looking for that kind of feature, try the above.
I found the best answer in: Interacting with program after execution
Quoting the answer below:
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
From output of python --help:
-i : inspect interactively after running script; forces a prompt even if stdin does not appear to be a terminal; also PYTHONINSPECT=x
To set interpreter option in PyCharm go to Run|Edit Configuration
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
I tried it and it works - simply use "-i" (without quotation marks) as "Interpreter options". Note that if you only change the Defaults in the Run/Debug Configurations, it may not take immediate effect for scripts you've already run before; you will need to edit the configurations of those scripts one by one.
This will enable a python shell (notice the green >>>
on the screenshot) where you can access all the variables in the current scope, and do everything you usually do in the Python shell.
In recent pycharm versions you get the full ipython interpreter instead of the plain python shell (if ipython is installed).
As a more comfortable alternative, if you only need to inspect some variables, access members or call methods on an object in scope, once a breakpoint is reached, select an expression in the current scope, right-click -> Evaluate Expression (or use the hotkey shown in the menu under Run → Evaluate Expression...), edit as needed — you can type any python expression, with auto-completion available — and then press Enter (or click Evaluate) to inspect the result.
Multiple and multiline expressions are supported: to get a multiline version of the Inspect dialog click the Code fragment mode or select more than one line of code in the editor and then evaluate the expression. You can assign values to existing variables (new ones cannot be defined), and run entire chunks of code.
To see the value of a variable after you hit a breakpoint in debug mode, hover the mouse pointer over the variable (1-2 seconds) and the value will be shown in a tooltip.
The hint will contain a ➕ icon — clicking it will open the inspector in a popup.
For the variables in scope the inspector is shown in the bottom panel under Debug > Debugger.
For pandas data frames you will see a View as DataFrame link in the variable inspector panel or in the hover popup — clicking the link will display the dataframe as a table in the Data View panel.
In the more recent Pycharm versions (2019+) the interpreter icon now looks different:
Also in the unittest/pytest debugging UI the icon is placed first in the icon bar.