[IPython-dev] running cells in notebook programmatically
Robert Alexander
roalexan at microsoft.com
Tue Dec 9 14:19:41 EST 2014
Hi. Running a script from the command line (using IPython 2.3.0) containing:
from IPython.nbformat import current as nbf
from IPython import get_ipython
nb = nbf.new_notebook()
firstCell = "print hello"
cells = [ nbf.new_code_cell(firstCell) ]
nb['worksheets'].append(nbf.new_worksheet(cells=cells))
ip = get_ipython()
print "ip"
print ip
for cell in nb.worksheets[0].cells:
if cell.cell_type != 'code':
continue
print "cell.input"
print cell.input
ip.run_cell(cell.input)
returns the error:
ip
None
cell.input
print hello
Traceback (most recent call last):
File "//.ipython/createnotebook.py", line 17, in <module>
ip.run_cell(cell.input)
AttributeError: 'NoneType' object has no attribute 'run_cell'
Is there a correct way to do this?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20141209/343afb16/attachment.html>
More information about the IPython-dev
mailing list