Calling a function from another notebook using `my_file.some_function()`

Is there a way to use the dot syntax in Jupyter Notebook to call a function that was defined in a different notebook? For example, suppose I have a notebook “test.ipynb” containing a function called square(x), and say we’ve imported test.ipynb using

using NBInclude
@nbinclude("test.ipynb")

Now that test.ipynb is imported, we can call square() just like a regular function, e.g. square(x). But for bookkeeping purposes, I’d like to call square by referencing the notebook in which it was defined in, e.g. test.square(x). Unfortunately I tried this and it didn’t work. Is there a similar way to do this?

nope, in order for test.square() to work, test must be a module. NBInclude doesn’t create one for you. and honestly that sounds like a bad idea. NBInclude at the moment works exactly like an include() with all the cell content stitched together in plain text.

Thanks for the answer. So I just have to create a module then…why would this be a bad idea?

the idea of single file as module (“automatically”, without having module end inside that file) sounds bad to me.