Save ipython notebook as script programmatically

后端 未结 2 1281
抹茶落季
抹茶落季 2021-01-06 17:19

The excellent ipython notebook has a handy --script command line flag that automatically saves a copy of the notebook as a .py script file (removin

2条回答
  •  悲&欢浪女
    2021-01-06 17:55

    Better yet (at least for my purposes): ipython respects local copies of the ipython_notebook_config.py file. So I can just add

    c = get_config()
    c.NotebookManager.save_script = True
    

    to such a file in my notebook directory. Apparently, ipython first reads ~/.ipython/profile_default/ipython_notebook_config.py, and then reads the local copy of that file. So it's safe to use without worrying about demolishing the user settings.

    This was not at all clear to me from the documentation, but I just tried it and it worked.

提交回复
热议问题