7

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)

flurble
  • 1,086
  • 7
  • 21

2 Answers2

10

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.

hiro protagonist
  • 44,693
  • 14
  • 86
  • 111
  • 4
    For anyone wondering, I checked this answer and it automatically detects the `# %%` delimiters for cells. – flurble Apr 30 '19 at 12:05
0

In addition to the above answer. Also this I have written a while ago (I am afraid I no longer maintain it) with references from here might still be working and be of use to you.

Here the example for spyder-like cell markers.

John Smith
  • 1,077
  • 6
  • 21