1

How to convert a jupyter notebook to a python script with cell delimiters (#%%)? I've already checked nbconvert , but it doesn't seem to have the one. Also, the same question found, the answer doesn't satisfy the need because actual raw source codes of jupyter notebook isn't structured as such. (It'd be better to be able to convert at once, instead of converting with nbconvert first and then pattern matching)

Any tools recommended? Or could you share a script to achieve this?

Mat Watershed
  • 45
  • 3
  • 7

1 Answers1

1

That looks similar to the percent delimiter that Jupytext handles, see the top few commands here also. The specific commands I'm referencing:

jupytext --to py:percent notebook.ipynb         # convert notebook.ipynb to a .py file in the double percent format
jupytext --to py:percent --opt comment_magics=false notebook.ipynb   # same as above + do not comment magic commands

See the bottom of the percent format section for more about that last command and further customization options.

Wayne
  • 6,607
  • 8
  • 36
  • 93