ipython. save notebook as script

Joint solution from http://stackoverflow.com/a/23619544 and http://stackoverflow.com/a/19067979

# [1]
%%javascript
var kernel = IPython.notebook.kernel;
var thename = window.document.getElementById("notebook_name").innerHTML;
var command = "theNotebook = " + "'"+thename+"'";
kernel.execute(command);

# [2]
try :
    if(__IPYTHON__) :
        get_ipython().system(u'ipython nbconvert --to python {}.ipynb'.format(theNotebook))
except NameError :
    pass

No comments:

Post a Comment