Code Sections
Code Sections provide a way to partition your script into regions that are independently executable (similar to notebook cells).
To define a code section, simply use a regular Python comment immediately followed by a :
as shown:
A code section extends from the line it's defined on until the beginning of the next section (or the end of the script if no further sections exist).
Execution
You can run a code section two ways:
By hovering over the section header and clicking on one of the execution buttons.
Using the keyboard shortcut (by default:
SHIFT
+ENTER
). This executes the code section that contains the current cursor position. If no code sections exist, the entire script is executed.
Regardless of which option you use, Scripton executes the code section (or a region relative to it) by issuing a /run
command with a range. For instance:
This tells Scripton to execute the code between lines 10
and 20
(both endpoints inclusive).
No Python Auto Restarts
Unlike regular executions (eg: via ⌘
+ R
, or by clicking on the toolbar Run button), code section executions do not auto-restart the Python process. This is intentional and enables notebook-style progressive and selective execution.