SoFunction
Updated on 2024-12-20

jupyter .ipynb to .py implementation operation

The jupyter written code is under the *.ipynb file, trying to introduce it in other python code will report an error, so it needs to be converted to standard python code in .py format.

jupyter nbconvert –to script 

Example:

try:
!jupyter nbconvert –to script 
except:
pass

Addendum: How to convert .py files and .ipynb files to each other in jupyter Notebook

01. Convert the .ipynb file to a .py file as shown;

02. Convert .py files to .ipynb files

First place the py file to be converted in the jupyter Notebook working directory;

Then create a new .ipynb file in jupyter Notebook;

In the newly created file type %load

Then you can open the file in juypyter Notebook in ipynb format;

Click Run, and the image below will appear:

Then click on "File" and "Download" to save it as a file in "ipynb format";

By doing the above you can convert .py files to .ipynb files

The above is a personal experience, I hope it can give you a reference, and I hope you can support me more. If there is any mistake or something that has not been fully considered, please do not hesitate to give me advice.