nbtof: transfering notebook to function
Project description
nbtof
This module is used to convert .ipynb file to .py function.
Intoroduction
Only by writing the #@~ marks in Jupyter Notebook file, you can easily convert Jupyter Notebook file to the python source file with the function which perform the same process as the Jupyter Notebook file. For example, in the case that you want to convert sample.ipynb to function,
sample.ipynb
#@param
a = 1
b = 1
c = a + b
#@return
c
you can get output.py by executing the next code.
import nbtof
nbtof.nbtof_generate(
notebook_name='sample.ipynb',
func_py_name='sample_output.py',
)
sample_output.py
def sample(a, b):
c = a + b
return c
Installation
The latest nbtof can be installed from PyPI:
pip install nbtof
Documantation
Marks list
| Mark | Description |
|---|---|
#@param |
Variable names in the cell become function's argument names. The values assigned at the Jupyter Notebook is ignored. |
#@default |
Variable names in the cell become function's argument names. The values assigned at the Jupyter Notebook get default values. |
#@args |
Variable names in the cell become function's variable length argument *args names. The values assigned at the notebook is ignored. |
#@kwargs |
Variable names in the cell become function's variable length argument **kwargs names. The values assigned at the notebook is ignored. |
#@return |
The line after this mark become function's return value |
#@ignore |
Anything in the cell is ignored. |
#@help |
What you write in the cell becomes function's docstring. Please write it in quotation marks. |
#@advance |
What you write in the cell is written before the function declaration as it is. (e.g., imports) |
#@r_advance |
The comment line with # in the cell is written with the # removed before the function declaration. (e.g., relative imports) |
Details about marks
#@param
The Jupyter Notebook
sample_param.ipynb
#@param
a = 0
print("Hello World !")
is converted into
def sample_param(a):
print('Hello world !')
#@default
The Jupyter Notebook
sample_default.ipynb
#@default
a = 0
print("Hello World !")
is converted into
def sample_default(a=0):
print('Hello world !')
#@default
The Jupyter Notebook
sample_default.ipynb
#@default
a = 0
print("Hello World !")
is converted into
def sample_default(a=0):
print('Hello world !')
#@args
sample_args.ipynb
#@args
a = 0
print("Hello World !")
is converted into
def sample_args(*a):
print('Hello world !')
#@kwargs
sample_kwargs.ipynb
#@kwargs
a = 0
print("Hello World !")
is converted into
def sample_kwargs(**a):
print('Hello world !')
#@return
#@ignore
#@help
#@advance
#@r_advance
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nbtof-0.0.7.tar.gz.
File metadata
- Download URL: nbtof-0.0.7.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c32a4f3072d188c57ce74a9c2353c8c8920c73a1c55d528b2030d86906ba7849
|
|
| MD5 |
092c764100958ed534f3b75e151bf3e0
|
|
| BLAKE2b-256 |
124dba1c15fa6a956c8b19fa31a1b009e8d43f340d3826f078699a0a312db0e5
|
File details
Details for the file nbtof-0.0.7-py3-none-any.whl.
File metadata
- Download URL: nbtof-0.0.7-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9f175a36b802b8aef16fef35d8375d4b06092cfd6c12caaf561dbb3fa5bf3a2
|
|
| MD5 |
e49c22334af037d5e3612ae307c55a03
|
|
| BLAKE2b-256 |
9fca677b4c56c407940be834088f8cc638d6a48680aa5aef84a0aeb511f41878
|