when using VSCode, I can run python files in cells/parts as if it was Jupyter notebook, without actually having a notebook.
https://code.visualstudio.com/docs/python/jupyter-support-py
It means, you can run a python file, part by part, iteratively, like in Jupyter Notebooks, but in .py
file.
it helps me to keep the code organized as a python file. (screenshot attached)
I wonder if the same feature exists in PyCharm. I couldn’t find it.
I attach a screenshot of the feature in VsCode when I can run simple python file in interactive mode, part by part.
thanks.
2
Answers
ok, answer found:
Magic Python in PyCharm PyCharm supports Magic Python cell execution. To use Magic Python, you need to enable Scientific Mode in the View menu. You can then use
#%%
to indicate the start and end of cells. Individual Cells can be executed in the console by pressing CTRL+Enter.In PyCharm, right-click on the root directory and select New > Python File. Give your file a meaningful name. Enter
Enable Scientific Mode in the View menu. Run the first cell by placing you mouse in the cell and pressing CTRL+Enter. Run the second cell by clicking on the Play button (arrow) that appears in the gutter of the editor.
source(and credit to): https://www.kevinsheppard.com/teaching/python/course/lesson-1/
The same feature exists in PyCharm.
Just right-click and select Execute selection in Python Console.