Issue
I have converted IPYNB format to PY format. It looks some what similar to that of jupyter notebook. [with cell number etc.]
E.g.:
#!/usr/bin/env python
# coding: utf-8
# In[19]:
e = 4
# In[25]:
if 'x' == 10
- if i convert this "PY format" back to "IPYNB format", i am getting entire program in the same cell, although we have cell numbers to differentiate
- Is there anyway to convert "PY format" back to "IPYNB format", with different cells, because I don't have the IPYNB files.
Solution
Quick and dirty option
Your example works easily using Jupytext.
In a terminal in your Jupyter session, where I saved your code example as test_dl_script.py
:
pip install jupytext
jupytext --to notebook test_dl_script.py
That gives threee notebooks cells with your two code lines separate.
For more complex things, it won't be perfect and would take some editing to the notebooks created.
In the future you are better off keeping the notebook files and using Jupytext when you want to convert. It goes back round trip correctly when it is used all the way through. See here.
More custom option
If you have way too many to deal with the imperfections you are going to see trying Jupytext and your notebook-derived code is very consistent with how markdown vs code cells is demarcated, you could custom script using nbformat to do this. I have posted several examples using nbformat with code and markdown cells in the Jupyter Discourse Forum that can be found here. Plus, there's several code blocks I have here at Stackoverflow using nbformat. (If you contact me via the Jupyter Discourse forum, I'd be more than happy to help you adapt nbformat to deal with the script code you have now to get it back to a notebook.)
Answered By - Wayne
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.