cancel
Showing results for 
Search instead for 
Did you mean: 
Community Platform Discussions
Connect with fellow community members to discuss general topics related to the Databricks platform, industry trends, and best practices. Share experiences, ask questions, and foster collaboration within the community.
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_Fatma
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

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group