ZGainsforth
8/2/2014 - 5:25 AM

Relative path in IPython Notebook

Relative path in IPython Notebook

First cell stores the path to a variable:

%%javascript
// This gets the name of the notebook so we can use     relative paths.
var kernel = IPython.notebook.kernel;
var thename = window.document.getElementById("notebook_name").innerHTML;
var command = "NotebookPath = " + "'"+thename+"'";
kernel.execute(command);

Later cells can use it:

FileName = os.path.join(os.path.dirname(NotebookPath), 'MMF.png')