[PYTHON] I made a tool to convert Jupyter py to ipynb with VS Code

Overview

Some VS Code extensions support Jupyter.

This is an excellent thing that can be executed in Jupyter as a Cell by writing # %%, but if you want to save it as .ipynb, copy and paste it to Jupyter's Cell on the browser every # %% It is necessary and troublesome.

So I made a tool to convert .py to .ipynb that contains # %%

Specifically

hello.py


#%%
print("Hello")

#%%
print("World!!")

If there is such a py

スクリーンショット 2017-06-16 16.57.56.png

Convert to ipynb like this

tool

This-> py2ipynb.py  Note that nbformat is required, but it should not be required separately as it will be installed together with pip install jupyter.

How to use

For example, if you want to convert hello.py, give it as an argument and execute it, and hello.ipynb will be generated in the same directory.

python py2ipynb.py hello.py

What you are doing internally

After all, it's simple because I just read py line by line, find out if there is a # %% at the beginning, and donbformat.v4.new_code_cell ().

It seems that the extension of VS Code is # %% and it is separated as Cell, so I'm just looking there.

Recommended Posts

I made a tool to convert Jupyter py to ipynb with VS Code
I made a code to convert illustration2vec to keras model
I made a tool to automatically browse multiple sites with Selenium (Python)
I was addicted to creating a Python venv environment with VS Code
Convert jupyter to py
I made a tool to compile Hy natively
I made a tool to get new articles
I made a QR code image with CuteR
Convert jupyter notebook .ipynb files to python executable .py files
I tried to build an environment with WSL + Ubuntu + VS Code in a Windows environment
I made a package to filter time series with python
I want to start a jupyter environment with one command
I made a tool to create a word cloud from wikipedia
I want to use a virtual environment with jupyter notebook!
[Titan Craft] I made a tool to summon a giant to Minecraft
Build a Python environment with WSL + Pyenv + Jupyter + VS Code
Convert .ipynb to .html (with BatchFile)
Try running Jupyter with VS Code
A tool to convert Juniper config
I made a daemon with Python
Are you still using Jupyter Notebook? Enjoy a comfortable Python life with Jupyter Life (.py) with VS Code ?!
[5th] I tried to make a certain authenticator-like tool with python
I made a library to easily read config files with Python
[2nd] I tried to make a certain authenticator-like tool with python
I made a web server with Raspberry Pi to watch anime
I wanted to create a smart presentation with Jupyter Notebook + nbpresent
[3rd] I tried to make a certain authenticator-like tool with python
[1st] I tried to make a certain authenticator-like tool with python
How to build Python and Jupyter execution environment with VS Code
I made a character counter with Python
I want to blog with Jupyter Notebook
I made a script to display emoji
I made a Hex map with Python
I made a life game with Numpy
I made a stamp generator with GAN
I made a browser automatic stamping tool.
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a WEB application with Django
I made a neuron simulator with Python
I wrote a code to convert quaternions to z-y-x Euler angles in Python
I tried to create a program to convert hexadecimal numbers to decimal numbers with python
[Django] I made a field to enter the date with 4 digit numbers
I tried to discriminate a 6-digit number with a number discrimination application made with python
I made a network to convert black and white images to color images (pix2pix)
I made a script in python to convert .md files to Scrapbox format
I made a tool that makes decompression a little easier with CLI (Python3)
I made a tool to estimate the execution time of cron (+ PyPI debut)
I made a stamp substitute bot with line
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.
I made a useful tool for Digital Ocean
I made a GUI application with Python + PyQt5
I created a tool to correct GPS data with Mapbox Map Matching API (Mapbox Map Matching API)
I made a tool to notify Slack of Connpass events and made it Terraform
I tried Flask with Remote-Containers of VS Code
I made a Twitter fujoshi blocker with Python ①
I want to make a game with Python
I made a tool to easily display data as a graph by GUI operation.
Easily convert Jupyter Notebooks to blogs with fastpages