Skip to content

Commit dad33cf

Browse files
committed
add two new keys to a cell
1 parent 2c8c14c commit dad33cf

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

execnb/nbio.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def set_source(self, source):
2828

2929
def parsed_(self):
3030
if self.cell_type!='code' or self.source.strip()[:1] in ['%', '!']: return
31-
if '_parsed_' not in self:
31+
if '_parsed_' not in self:
3232
try: self._parsed_ = ast.parse(self.source).body
3333
# you can assign the result of ! to a variable in a notebook cell
3434
# which will result in a syntax error if parsed with the ast module.
@@ -70,6 +70,9 @@ def mk_cell(text, # `source` attr in cell
7070
"Create an `NbCell` containing `text`"
7171
assert cell_type in {'code', 'markdown', 'raw'}
7272
if 'metadata' not in kwargs: kwargs['metadata']={}
73+
if cell_type == 'code':
74+
kwargs['outputs']=[]
75+
kwargs['execution_count']=0
7376
return NbCell(0, dict(cell_type=cell_type, source=text, directives_={}, **kwargs))
7477

7578
# %% ../nbs/01_nbio.ipynb 31

nbs/01_nbio.ipynb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@
171171
"\n",
172172
" def parsed_(self):\n",
173173
" if self.cell_type!='code' or self.source.strip()[:1] in ['%', '!']: return\n",
174-
" if '_parsed_' not in self: \n",
174+
" if '_parsed_' not in self:\n",
175175
" try: self._parsed_ = ast.parse(self.source).body\n",
176176
" # you can assign the result of ! to a variable in a notebook cell\n",
177177
" # which will result in a syntax error if parsed with the ast module.\n",
@@ -394,6 +394,9 @@
394394
" \"Create an `NbCell` containing `text`\"\n",
395395
" assert cell_type in {'code', 'markdown', 'raw'}\n",
396396
" if 'metadata' not in kwargs: kwargs['metadata']={}\n",
397+
" if cell_type == 'code':\n",
398+
" kwargs['outputs']=[]\n",
399+
" kwargs['execution_count']=0\n",
397400
" return NbCell(0, dict(cell_type=cell_type, source=text, directives_={}, **kwargs))"
398401
]
399402
},

0 commit comments

Comments
 (0)