1

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

Any ideas?

Nick is tired
  • 6,860
  • 20
  • 39
  • 51
dcs
  • 9
  • 5

1 Answers1

1

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

Mortz
  • 4,654
  • 1
  • 19
  • 35