def py2ipynb_default(input, output): with open(input) as f: code = f.read() code += """ # <markdowncell> # If you can read this, reads_py() is no longer broken! """ nbook = v3.reads_py(code) nbook = v4.upgrade(nbook) # Upgrade v3 to v4 jsonform = v4.writes(nbook) + "\n" with open(output, "w") as f: f.write(jsonform)
def py_to_ipynb(filname): with open(filname+".py",encoding="utf8", errors='ignore') as fpin: text = fpin.read() text += """ <markdowncell> If you can read this, reads_py() is no longer broken! """ nbook = v3.reads_py(text) nbook = v4.upgrade(nbook) # Upgrade v3 to v4 jsonform = v4.writes(nbook) + "\n" with open(filname+".ipynb", "w") as fpout: fpout.write(jsonform)
#Convert feature engg example python file to jupyter .ipynb #https://stackoverflow.com/questions/23292242/converting-to-not-from-ipython-notebook-format from IPython.nbformat import v3, v4 with open("feature_engg_example.py") as fpin: text = fpin.read() nbook = v3.reads_py(text) nbook = v4.upgrade(nbook) # Upgrade v3 to v4 jsonform = v4.writes(nbook) + "\n" with open("03_feature_engg_examples.ipynb", "w") as fpout: fpout.write(jsonform)