Repository navigation
File formats
gpython reads and writes four formats. It writes a file back in the format that it had.
| Format | How gpython knows it | Cell borders are stored |
|---|---|---|
Plain .py script |
No # %% lines, not marimo |
Outside the file, in ~/.gpython/cells
|
.py with # %% cells |
The file has # %% lines |
In the file |
| marimo notebook |
import marimo and @app.cell functions |
In the file |
| Jupyter notebook | The .ipynb extension |
In the file |
__file__ and the working folder of the kernel are those of the notebook.
This is the same as when you run the file as a script.
- gpython divides the script into cells at top-level statements.
- gpython saves the file without
# %%lines. Thus the script stays an ordinary script. - A new notebook that you save as
.pyis also a plain script. - A top-level
"""text"""string is a markdown cell.
gpython keeps this data outside the file, in ~/.gpython/cells:
- Where each cell starts and ends.
- Which cells are markdown and which cells have hidden code.
- The last outputs, the run number and the run time of each code cell.
When you open the file again, the cells and their outputs come back. If a different editor changed the file, gpython divides it into cells again. More details are in Configuration.
This is the format of VS Code and Jupytext.
| Line | Meaning |
|---|---|
# %% |
A code cell starts |
# %% [markdown] |
A markdown cell starts. Its lines start with #
|
A file that has # %% lines keeps them when you save.
To get this format from a plain script, use :copy all metadata. It copies the notebook to the
clipboard with the # %% lines.
gpython opens the @app.cell functions as cells.
If you change nothing, gpython saves the file byte for byte the same.
| Item | Kept |
|---|---|
| Cell names | Yes |
hide_code=True |
Yes. Such cells open with hidden code. h in cell mode shows it |
mo.md(...) cells |
Yes. gpython shows them as markdown and does not run them |
| Other decorator arguments | No |
Comments after the return of a cell |
No |
In the kernel, a small marimo substitute supplies mo.md, mo.Html, mo.hstack,
mo.vstack and placeholders for mo.ui. Thus these notebooks run.
| Item | On open | On save |
|---|---|---|
| Code and markdown cells | Loaded | Saved |
| Outputs | Loaded | Saved with the current outputs |
| Run numbers | Loaded | Saved |
| Notebook metadata | Kept | Kept |
| Command | What goes to the clipboard |
|---|---|
:copy |
This cell |
:copy all |
The notebook as code. Markdown cells become comments |
:copy all metadata |
The same, with the # %% lines |
Use the notebook
- Getting started
- Command line
- Running cells
- Keys
- Commands
- Vim
- Markdown cells
- Variables and the debugger
- Images
Set up the workspace
Help and project