Scripton / Docs

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:

import torch #: This is a section. Note the colon (:) immediately after the '#'. # This is a regular comment with no special significance. model = torch.hub.load( 'pytorch/vision:v0.10.0', 'resnet18', pretrained=True ) model.eval() #: This is another section. input_image = ...

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:

  1. By hovering over the section header and clicking on one of the execution buttons.

  2. 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:

/run my_script[10:20]

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.