问题
I mostly use Spyder for my data analysis and am quite satisfied with it. There you can use the cell functionality of Jupyter Notebooks in normal python scripts using # %%
to delimit individual code cells (and also execute blocks). The same thing is also possible in Atom with Hydrogen.
What I am looking for is a way to convert these scripts into a jupyter notebook, automaticlally splitting cells at each # %%
. The notebook I would use to document, explain and share my workflow by inserting some markdown and possibly saving as pdf or html.
Can the conversion be done automatically? Is this perhaps doable with nbconvert
? (I only use it the other way around: jupyter -> python)
回答1:
there is jupytext (also available on pypi) that can convert from ipynb
to several formats and back.
when jupytext
is installed you can use
$ jupytext --to notebook test.py
in order to generate test.ipynb
.
jupytext
has a lot more interesting features that can come in handy when working with notebooks.
来源:https://stackoverflow.com/questions/55919667/how-to-convert-a-python-script-with-cell-delimiters-to-a-jupyter-notebook