jupyter-incubator / contentmanagement

Jupyter Content Management Extensions
Other
78 stars 26 forks source link

A way to inject variables into the notebook's namespace before loading the notebook #40

Closed post2web closed 8 years ago

post2web commented 8 years ago

It will be very useful if I could do this:

mynb = load_notebook('mynb.ipynb', locals=dict(a=5))
print mynb.a

I know I can set mynb.a = 5 after it has been imported but a way to inject local variables before importing could create very interesting workflows.

Another way this could potentially look like:

mynb = load_notebook('mynb.ipynb', execute=False)
mynb.a = 5
mynb.execute()
print mynb.a

I would appreciate any workaround ideas.

parente commented 8 years ago

This is a neat idea.

As you can tell, we haven't been spending much time over here in the CMS extension vs some of our other incubator projects. We'll gladly take a PR if you'd like to give it a shot.