Notebooks in the Databricks aren't the real files - they are something like an entry in the database not stored on the file system. Because of this you can't use Python's import
to code from one notebook into another.
Right now it's possible to use %run
to include content of one notebook into another (see docs), for example, to implement testing of notebooks. Just split your code into two pieces:
- Notebook with functions that you want to test (name it
functions
, for example):
def func1(....):
....
- And in the notebook with test code put the following as a separate cell
%run ./functions
this will include the whole content of the first notebook into context of the second notebook.
I have a demo project that shows how to use this approach to test notebooks on Databricks.
P.S. There is a workaround by downloading the notebooks onto local file system, adding them to sys.path
, etc., but it's cumbersome - you can find an example in the following answer.