'Converting .py files to .ipynb
My organisation converts any Jupyter Notebooks (.ipynb files) it makes into python scripts (.py files) for easier management in our repos. I need to convert them back so I can run the notebooks but can't work out how.
I believe they've been encoded using the nbconvert package but I couldn't find a way to convert the files back in the package docs.
I've included the head of one of the .py files bellow in case it makes the encoding format more obvious.
# ---
# jupyter:
# jupytext:
# formats: ipynb,py:light
# text_representation:
# extension: .py
# format_name: light
# format_version: '1.4'
# jupytext_version: 1.2.0
# kernelspec:
# display_name: Python 3
# language: python
# name: python3
# ---
# # Title/filename here
# ### Initialise
import pandas as pd
import numpy as np
# etc
# ### Title here
# +
do_stuff()
Solution 1:[1]
Looks like the file was actually converted using program jupytext.
To convert it back I found running jupytext --to ipynb my_file.py worked.
More simply: opening the .py file in jupyter notebook aloud me to view the .py file as if it were a .ipynb file without converting.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Red Grassrex |
