cancel
Showing results for 
Search instead for 
Did you mean: 
Community Discussions
cancel
Showing results for 
Search instead for 
Did you mean: 

how to save variables in one notebook to be imported into another?

kll
New Contributor III

Say, I have a list of values, dictionaries, variable names in `notebook1.ipynb` that I'd like to re-use / import in another `notebook2.ipynb`. 

For example, in `notebook1.ipynb`, I have the following: 

 

 

var1 = "dallas"

var_lst = [100, 200, 300, 400, 500]

 

 

How do I save this to disk and read / import in `notebook2.ipynb` ?  

2 REPLIES 2

Kaniz
Community Manager
Community Manager

Hi @kll , To save variables from notebook1.ipynb and import them in notebook2.ipynb, you can use Python's built-in pickle module.

Krishnamatta
New Contributor III

You can use %run ./notebook2 after defining variables in notebook1

So notebook2 will use the variables defined in notebook1

Welcome to Databricks Community: Lets learn, network and celebrate together

Join our fast-growing data practitioner and expert community of 80K+ members, ready to discover, help and collaborate together while making meaningful connections. 

Click here to register and join today! 

Engage in exciting technical discussions, join a group with your peers and meet our Featured Members.