Import notebook content into a python file

thibault
Contributor III

Hi, I have a workflow based on python scripts. How can I import the content of a notebook where a class and functions are defined?

I know how to import python files into notebooks, but the other way around doesn't seem as straight forward.

thibault
Contributor III

Found a solution executing a notebook, using the databricks api to download the notebook content as bytes :

1. set environment variables DATABRICKS_HOST and DATABRICKS_TOKEN

2. 

w = WorkspaceClient()
with w.workspace.download(notebook_path) as n:
notebook_content = n.read()
exec(notebook_content, globals())

View solution in original post