How to convert a python script with cell delimiters to a jupyter notebook?

醉酒当歌 提交于 2019-12-10 19:40:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!