3

I am a new user of Mathematica. I want to import a variable from notebook-1 to notebook-2 where I am currently using. I have searched for Mathematica repository but unfortunately I could not find an answer to my question.

Suppose that I have:

var=23

in notebook-1 and I want to import var into notebook-2.

user64494
  • 26,149
  • 4
  • 27
  • 56
  • 2
    If you happen to run notebooks with unique contexts like I do, then a simple Export[myFileName,var] in notebook 1 then var=Import[myFileName] in notebook 2 would work. – josh Apr 19 '23 at 14:49

1 Answers1

5

By default, notebooks share the same variables.

So when you type var=23 in one notebook, and open second notebook and type var, it will say 23.

So you do not have to do anything to import the variable.

enter image description here

To disable this, you need to do

Evaluation menu -> Notebook's Default Context -> Unique to This Notebook.

And now variables created in the notebook are no longer shared/visible in other notebooks.

Reference

Is there a way to separate variables between multiple notebooks?

Nasser
  • 143,286
  • 11
  • 154
  • 359