Recommenders: Script to transform notebooks to python files

Created on 12 Nov 2018  路  5Comments  路  Source: microsoft/recommenders

Requested by Graham

enhancement

Most helpful comment

@loomlike some other things to bear in mind are the magic commands used in the notebooks that may behave unexpectedly.

All 5 comments

@miguelgfierro we can use this command (or just add document about a user can convert any notebook by using the following command? what do you think?):

jupyter nbconvert --to script notebook.ipynb
(to other formats, see https://ipython.org/ipython-doc/3/notebook/nbconvert.html)

Here is the example of the conversion results of SAR single node quickstart notebook. See how the cell number and markdown cells are converted:

"# # SAR on MovieLens (Python, CPU)"
"# SAR is a fast scalable adaptive algorithm for ..."
.....

"# # 0 Global Settings and Imports"

"# In[2]:"

"# set the environment path to find Recommenders"
import sys
sys.path.append("../../")

import os
...

(added " because of the github auto conversion to md)

The only Some (see below Le's comment ;-) constraints of this conversion is the notebook module usage, like 'display()'
I tested conversion and run the converted script. It runs well until it sees 'display' call and got error:
NameError: name 'display' is not defined

@loomlike some other things to bear in mind are the magic commands used in the notebooks that may behave unexpectedly.

as mentioned by Le, this should work:

jupyter nbconvert --to script notebook.ipynb

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anargyri picture anargyri  路  4Comments

ngcferreira picture ngcferreira  路  4Comments

roalexan picture roalexan  路  4Comments

luiscastro193 picture luiscastro193  路  5Comments

yueguoguo picture yueguoguo  路  4Comments