Joint solution from [http://stackoverflow.com/a/23619544](http://stackoverflow.com/a/23619544" target="_blank) and [http://stackoverflow.com/a/19067979](http://stackoverflow.com/a/19067979" target="_blank)

# [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