cancel
Showing results for 
Search instead for 
Did you mean: 
Community 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

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!