Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automated conversion between .py and .ipynb #22

Open
sbcowan opened this issue Mar 14, 2023 · 0 comments
Open

Automated conversion between .py and .ipynb #22

sbcowan opened this issue Mar 14, 2023 · 0 comments

Comments

@sbcowan
Copy link
Collaborator

sbcowan commented Mar 14, 2023

While there are ways to convert the .ipynb to .py and vice versa, both directions bring certain unwanted issues that should be addressed.

From .ipynb to .py
The go-to way is to use jupyter nbconvert --to script 'example.ipynb'. This results in a working example. This can be followed up with using the clean_py_notebooks.py to make them more usable, however there are still empty quotes left over. Furthermore, it converts all the files in hard coded directories.

Solution:

  1. Improve clean_py_notebook.py to get rid of empty """ strings.
  2. Create a script that combines the command above with the clean_py_notebooks.py file so that the conversion from .ipynb to .py is seamless. The script should allow you to both choose specific files to be converted, and in addition also convert whole example libraries.

From .py to .ipynb
This direction is of lesser importance because the .ipynb will remain the actively developed examples. There are two options:

  • The convert_py_to_ipynb.py file just creates one big code cell in a .ipynb file.
  • The p2j (installed with pip) package does allocate code and markdown cells properly, but introduces countless <br> instances and does not allocate headers in markdown cells consistently.

The two options are both sub-optimal, which could use more work in the future also by means of a script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: tudatpy-examples
Development

No branches or pull requests

1 participant