New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Populate local context with variables from imported notebook #25
Comments
Thanks for opening this. I think I'm missing what you're asking, but let me try to answer and you can tell me where I'm off base. If you annotate a cells with |
Thank you for clarifying. The solves my problem. |
Hm. Interesting that the prefix did not work. What platform are you on? There's a defect open about Windows and I wonder if this is a hint about what's wrong there. |
I'm on OSX. What sort of information might be insightful? |
I've got a Mac so let me try that here before I bug you for more info. |
Hm. I just did:
Then I created a.ipynb with content:
I next created b.ipynb with content:
It works and shows the output as
which works as well. Finally, I tried:
which also works, but shouldn't by design. |
Is jupyter_cms python 3 - only and I have missed that? with
I get
with
With
|
The plot thickens: It should work in 2.7 too. In fact, my Mac test above was run against 2.7. |
Are you annotating the cell with |
Oh my, this is getting more and more obscure. I activated 2.7 venv again and now your original code runs fine. So I went back to my actual work and again I then copied the imported file ( Now the weird thing: I copied |
If you start introducing subfolders, you need to make sure you add the subfolder to any absolute module import. So if you've now got:
and you're doing the import in If the module magic is getting you down, there's also a function form of the same capability which doesn't have any module magic. It's described in the tutorial here https://github.com/jupyter-incubator/contentmanagement/blob/master/etc/notebooks/cookbooks_demo/use_cookbooks.ipynb. All that said, |
Sorry, I wasn't clear enough. I started the notebook server in the subfolder. In other words. I moved the files to the subfolder, quite the original server, cd'ed into the subfolder So, the notebook index shows these files directly - not inside of a folder.
I thought there is some reference to the path in the metadata but a Regarding the function form - this is what I started with, but that did not allow me to execute the imported notebook (e.g. |
OK. Looks like I have more digging to do.
That's right. You get a module back with all the objects from that notebook hanging off it. You might be able to play tricks with a loop to copy everything from that module into the local globals, but, yuck. :) |
Hi,
I would like to see the capability to have variables defined in my imported notebook (e.g. in # cells) to also be available in my importing notebook. This feature would allow me to split up logic from large notebooks into smaller notebooks.
At the moment, I need to inject and execute all code into my importing notebook in order to get access to any variable state.
Any comments if such an option would be desirable/feasible?
Many thanks.
The text was updated successfully, but these errors were encountered: