Databricks %run command not using a variable value from called notebook
20:53 11 Mar 2026

Question: When Notebook_A is executed, it's not displaying value of my_variable. Why?

Remarks: I though you can use %run command to make variables defined in one notebook available in another. The %run command executes the specified notebook inline within the current notebook's session, so all functions, variables, and DataFrames defined in the called notebook become accessible in the calling notebook.

PLEASE NOTE: Question is NOT about achieving the same using alternatives such as dbutils.notebook.exit() etc. It's rather this code is not working

Notebook_A

my_variable = "Hello from Notebook A"

Notebook_B

cell_1

%run ./Notebook_A

cell_2


# Now you can use the variable defined in Notebook_A
print(my_variable)

Output of cell_2:

my_variable

Expected output of cell_2:

Hello from Notebook_A
python databricks spark-notebook azure-notebooks