1

Assume you have a .ipynb file with code cells and normal text for a proyect. I've been looking for ways to extract "code" cells directly to a .py file so i can mess with it and upload it on my standard format to Github.

I've tried parsing with awk, but due to the format having " in front of code lines and ASCII formatting, i'm out of clues. Are there any libraries, or ways to accomplish this without having to copypaste every code cell from the Notebook to my .py file? As i have one file for each proyect, feels dull to do this every time.

Thanks in advance!

1 Answer 1

1

You should be able to use the nbconvert command for both ipython and jupyter:

ipython nbconvert --to=python [YOUR_NOTEBOOK].ipynb

or

jupyter nbconvert --to=python [YOUR_NOTEBOOK].ipynb

If you're doing this for a lot of notebooks you can pass wildcard into the argument! The line below will convert every ipynb file in a folder to .py scripts!

jupyter nbconvert --to=python /SOME/PATH/my_notebooks/*.ipynb
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.