Cell mode in Python editors

Viewed 13189

In recent versions of MATLAB, one can execute a code region between two lines starting with %% using Ctrl-Enter. Such region is called a code cell, and it allows for fast code testing and debugging.

E.g.

%% This is the beginning of the 1st cell

a = 5;    

%% This is the end of the 1st cell and beginning of the 2nd cell

% This is just a comment
b = 6;

%% This is the end of the 2nd cell

Are there any python editors that support a similar feature?

EDIT: I just found that Spyderlib supports "block" execution (code regions separated with blank lines) with F9, but as the this thread mentions, this feature is still not very robust (in particular in combination with loops).

7 Answers

Spyder3 & PyCharm: #%% or # %%

Spyder3: Ctrl+Enter: to run current cell, Shift+Enter: to run current cell and advance.

PyCharm: Ctrl+Enter: to run and advance

# %%

print('You are in cell 1')

# %%

print('You are in cell 2')
# %% 

print('You are in cell 3')

enter image description here

Related