Skip to content

Commit 5dd7376

Browse files
authored
Merge pull request #23 from dleen/master
Add new nb function
2 parents 522254b + ca49b25 commit 5dd7376

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

execnb/_modidx.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
'execnb.nbio.dict2nb': 'https://fastai.github.io/execnb/nbio.html#dict2nb',
5151
'execnb.nbio.nb2dict': 'https://fastai.github.io/execnb/nbio.html#nb2dict',
5252
'execnb.nbio.nb2str': 'https://fastai.github.io/execnb/nbio.html#nb2str',
53+
'execnb.nbio.new_nb': 'https://fastai.github.io/execnb/nbio.html#new_nb',
5354
'execnb.nbio.read_nb': 'https://fastai.github.io/execnb/nbio.html#read_nb',
5455
'execnb.nbio.write_nb': 'https://fastai.github.io/execnb/nbio.html#write_nb'},
5556
'execnb.shell': { 'execnb.shell.CaptureShell': 'https://fastai.github.io/execnb/shell.html#captureshell',

execnb/nbio.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_nbio.ipynb.
22

33
# %% auto 0
4-
__all__ = ['NbCell', 'dict2nb', 'read_nb', 'nb2dict', 'nb2str', 'write_nb']
4+
__all__ = ['NbCell', 'dict2nb', 'read_nb', 'nb2dict', 'nb2str', 'write_nb', 'new_nb']
55

66
# %% ../nbs/01_nbio.ipynb 2
77
from fastcore.imports import *
@@ -65,3 +65,8 @@ def nb2str(nb):
6565
def write_nb(nb, path):
6666
"Write `nb` to `path`"
6767
with maybe_open(path, 'w', encoding='utf-8') as f: f.write(nb2str(nb))
68+
69+
# %% ../nbs/01_nbio.ipynb 35
70+
def new_nb():
71+
"Returns an empty new notebook"
72+
return dict2nb({'cells':[],'metadata':{},'nbformat':4,'nbformat_minor':5})

nbs/01_nbio.ipynb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,32 @@
446446
"finally: tmp.unlink()"
447447
]
448448
},
449+
{
450+
"cell_type": "markdown",
451+
"metadata": {},
452+
"source": [
453+
"# Creating a notebook"
454+
]
455+
},
456+
{
457+
"cell_type": "code",
458+
"execution_count": null,
459+
"metadata": {},
460+
"outputs": [],
461+
"source": [
462+
"#|export\n",
463+
"def new_nb():\n",
464+
" \"Returns an empty new notebook\"\n",
465+
" return dict2nb({'cells':[],'metadata':{},'nbformat':4,'nbformat_minor':5})"
466+
]
467+
},
468+
{
469+
"cell_type": "markdown",
470+
"metadata": {},
471+
"source": [
472+
"Use this function when creating a new notebook. Useful for when you don't want to create a notebook on disk first and then read it."
473+
]
474+
},
449475
{
450476
"cell_type": "markdown",
451477
"metadata": {},

0 commit comments

Comments
 (0)