Convert Jupyter notebooks to Hydrogen / VScode / Spyder compatible scripts, and back
See original GitHub issueMany editors recognize code cells in python scripts as blocks that start with # %%
, including
- Hydrogen
- VS code
- Spyder.
I found no specific marker for markdown () or raw cell yet. So let’s be inventive and imagine a few specifications for that format: any cell starts with the above prefix. An optional cell type (among: code, markdown, raw) can be specified. An optional cell name can be stated (it cannot be any of code, markdown, raw). Then, if required, we add the cell metadata, in JSON format, like in the following:
# %% optional_cell_type optional_cell_name {"metadata_key1": "value1", "key2": "value2"}
import pandas as pd
pd.DataFrame({'A':[5]}).plot(kind='bar')
# %% markdown
# This is a markdown cell
# %%
# # This is a commented code cell
# import pandas
Hydrogen and VS code execute python code with Jupyter kernels, so there’s no need to escape Jupyter magics here.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Working with Jupyter Notebooks in Visual Studio Code
Export your Jupyter Notebook You can export a Jupyter Notebook as a Python file ( . py ), a PDF, or an HTML...
Read more >Jupytext documentation
Jupytext is a plugin for Jupyter that can save Jupyter notebooks as ... write notebooks as Hydrogen/VScode/Spyder/PyCharm compatible scripts ...
Read more >jupytext - PyPI
jupytext converts Jupyter notebooks to their text representation, and back. The command line tool can act on notebooks in many ways. It can ......
Read more >jupyter kernels
The Jupyter Notebook integrates code and its output into the single document ... assignments. with shell kernels you can turn your scripts into...
Read more >How to structure your Python scripts for Sphinx-Gallery
This will be rendered in-line with the Python code and its outputs, similar to how Jupyter Notebooks are structured (in fact, Sphinx-Gallery also...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@danieltomasz , thanks for your example. I just changed the format parser to make sure your example will open as a ‘percent’ script. The identification of spyder scripts now requires just one cell in the script, that’s a simpler criterion!
Well, yes. You should add a least a second cell… this is briefly documented in the next README. Let me explain a bit more…
When no format information is given, jupytext classifies percent scripts as such if they contain at least two explicit cells. What’s happening here is that jupytext opens your script as a standard Python script, using the
light
format.Note that if you generate the percent script using Jupytext, a YAML header with an explicit information on the file format will be added, and Jupyter will open it with the right format.