deathbeds / importnb

notebook files as source
https://importnb.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
68 stars 5 forks source link

Import only definitions, classes while avoiding other statements #116

Closed davidleejy closed 2 years ago

davidleejy commented 3 years ago

Is it possible to do the equivalent of import ipynb.fs.defs.notebook123 in importnb? This imports only definitions in notebook123.ipynb and avoids other statements. For e.g. if there's a statement foo='hi' in notebook123.ipynb, it does not get imported.

I think this is a useful feature since there might be executable statements in notebook123.ipynb that demonstrate how the functions work and are kept uncommented in the notebook for debugging and communicative purposes. Would be neat if these statements aren't imported.

tonyfast commented 2 years ago

this feature is added by #127 . it will be important to note the caveat that global variables cant be used in local scopes when this behavior is activated.

jeroenvuurens commented 1 year ago

This does not work anymore?

tonyfast commented 1 year ago

seems to work for me when i use the include_non_defs=False.

my example notebook has a print statement that should display when include_non_defs is True:

image

the following cells show loading with this style behavior.

image