Amelio Vazquez-Reina Amelio Vazquez-Reina - 1 year ago 110
Python Question

Cell mode in Python editors

In recent versions of MATLAB, one can execute a code region between two lines starting with

. Such region is called a code cell, and it allows for fast code testing and debugging.


%% 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).

Answer Source

The Interactive Editor for Python IEP has a Matlab-style cell notation to mark code sections (by starting a line with '##'), and the shortcut by default is also Ctrl+Enter:

## Cell one
A cell is everything between two commands starting with '##'
a = 3
b = 4
print('The answer is ' + str(a+b))

## Cell two

print('Hello World')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download