Home > other >  Does PyCharm have the feature for executing python script in parts/cells (like in VsCode - Run in in
Does PyCharm have the feature for executing python script in parts/cells (like in VsCode - Run in in

Time:01-03

when using VSCode, I can run python files in cells/parts as if it was Jupyter notebook, without actually having a notebook. enter image description here

enter image description here

CodePudding user response:

The same feature exists in PyCharm.

Just right-click and select Execute selection in Python Console.

Selection

Execution

CodePudding user response:

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

#%%
print("This is the first cell")
#%%
print("This is not executed when the first cell is run")

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.

enter image description here

source(and credit to): https://www.kevinsheppard.com/teaching/python/course/lesson-1/

  • Related