How do I convert a IPython Notebook into a Python file via commandline?

后端 未结 10 2585
一生所求
一生所求 2020-11-29 14:42

I\'m looking at using the *.ipynb files as the source of truth and programmatically \'compiling\' them into .py files for scheduled jobs/tasks.

The

10条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 14:50

    If you don't want to output a Python script every time you save, or you don't want to restart the IPython kernel:

    On the command line, you can use nbconvert:

    $ jupyter nbconvert --to script [YOUR_NOTEBOOK].ipynb
    

    As a bit of a hack, you can even call the above command in an IPython notebook by pre-pending ! (used for any command line argument). Inside a notebook:

    !jupyter nbconvert --to script config_template.ipynb
    

    Before --to script was added, the option was --to python or --to=python, but it was renamed in the move toward a language-agnostic notebook system.

提交回复
热议问题