How to share variables between two different Jupyter notebooks ?

Let’s say we have two Jupyter notebooks and we need to share a variable from first notebook to the second notebook.

How can we do that?

Jupyter provides magic commands to ease operations which are complex otherwise. The magic command we are going to use today is %store.

The %store magic command saves the specified variable and lets you pass the value of variables between two notebooks.

Lets see how we can pass the variable value:
%store x #x is a variable to share

and now how to retrieve the value in other notebook:
%store -r x

Happy Learning !!!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s