3
$\begingroup$

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.

$\endgroup$
1
  • 2
    $\begingroup$ 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. $\endgroup$
    – josh
    Commented Apr 19, 2023 at 14:49

1 Answer 1

5
$\begingroup$

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?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.