Convert Json Ipython Notebook(.ipynb) To .py File


Answer :

From the notebook menu you can save the file directly as a python script. Go to the 'File' option of the menu, then select 'Download as' and there you would see a 'Python (.py)' option.



enter image description here



Another option would be to use nbconvert from the command line:



jupyter nbconvert --to script 'my-notebook.ipynb'


Have a look here.



According to https://ipython.org/ipython-doc/3/notebook/nbconvert.html you are looking for the nbconvert command with the --to script option.



ipython nbconvert notebook.ipynb --to script


In short: This command-line option converts mynotebook.ipynb to python code:



jupyter nbconvert mynotebook.ipynb --to python



note: this is different from above answer. ipython has been renamed to jupyter. the old executable name (ipython) is deprecated.






More details:
jupyter command-line has an nbconvert argument which helps convert notebook files (*.ipynb) to various other formats.



You could even convert it to any one of these formats using the same command but different --to option:




  • asciidoc

  • custom

  • html

  • latex. (Awesome if you want to paste code in conference/journal papers).

  • markdown

  • notebook

  • pdf

  • python

  • rst

  • script

  • slides. (Whooh! Convert to slides for easy presentation )



the same command jupyter nbconvert --to latex mynotebook.ipynb



For more see jupyter nbconvert --help. There are extensive options to this. You could even to execute the code first before converting, different log-level options etc.



Comments

Popular posts from this blog

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"

Android How Can I Convert A String To A Editable