1

I have some Jupyter notebooks and I want them to be executed using a main.py file.

Any ideas?

Nick is tired
7,17721 gold badges44 silver badges55 bronze badges
asked Nov 26, 2021 at 9:17

1 Answer 1

2

You can convert the .ipynb file to a plain .py file using any of the methods mentioned here -

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

If, like me, you don't have access to the command line tools required - you can extract the source code from the .ipynb file as it is mostly a json file

import json
with open('somefile.ipynb') as f:
 nb_content = json.load(f)
for cell in nb_content['cells']:
 print(*cell['source'])

That should print out the whole source code to your terminal

answered Nov 26, 2021 at 9:36
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.