Skip to content

Instantly share code, notes, and snippets.

@ZGainsforth
Created August 2, 2014 05:25
Show Gist options
  • Select an option

  • Save ZGainsforth/ca33097c522b438025f7 to your computer and use it in GitHub Desktop.

Select an option

Save ZGainsforth/ca33097c522b438025f7 to your computer and use it in GitHub Desktop.
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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment