5 Standalone Script
Using Atom's Hydrogen package, you can execute any Python script codes within a fenced code block in a Markdown source. So you can edit your code verifying its execution results. But unfortunately (as long as I know), the entire Markdown source cannot be executed all at once as a standalone script and cannot be ran by Python interpreter. Pheasant connects between a pure Python script and a Markdown source. Actually, this page is written by a pure Python code.
5.1 How to
A basic idea is that Markdown cells and Python code cells generally appear alternately. We can write a Markdown cell with a successive comment lines. In order to be recognized as a Markdown cell,
# must be at the begining of lines. But we can insert a blank line to make a paragraph.
Normal Python code is treated as a code cell as you expect.
def add(x: int, y: int) -> int: """Add `x` and `y`.""" return x + y def sub(x: int, y: int) -> int: """Substract `y` from `x`.""" return x - y
 2020-12-20 08:15:14 (10.0ms) python3 (1.55s)
When a comment starts at the begining of line after a code block, it divides the source into a code cell and a Markdown cell. This new Markdown cell will continue until next Python code appears.
If you want to include a comment at the begining of line, you can write the comment just above the following codes without a blank line.
# First comment in a code cell. a = 2
 2020-12-20 08:15:14 (14.0ms) python3 (1.57s)
Despite of a Markdown cell, you may want to devide successive codes into separate cells. This can be done by putting a special inline comment to define a cell. The comment pattern is
# -. For example,
a, b, c = 1, 2, 3 a
 2020-12-20 08:15:14 (7.89ms) python3 (1.57s)
 2020-12-20 08:15:14 (13.1ms) python3 (1.59s)
You can add options to a code block by adding them after a cell devider.
Above python code is equivalent to the next Markdown source.
Then you can hide the python code cell.
dis equal to 4.
5.2 Fenced code block in Python source
You can write a fenced code block in a Python source as comment.
 2020-12-20 08:15:14 (14.0ms) python3 (1.63s)
5.3 A package for comment formatting
In this scheme, we have to write many comments for Markdown cells. But a linter such as pycodestyle doesn't allow us to write a very long comment in one line longer than (for example) 79 characters. This means that we have to write Markdown source with several new line characters even we are writing one paragraph. In order to overcome this incovenient situation, a comment formatting pakage
pyls-cwrap has been prepared. You can install this package as
pip install pyls-cwrap. In Atom, if you use
ide-python, just press [Ctrl]+[Shift]+[C] (Windows, default setting), sequential comments are automatically formatted nicely.