4
$\begingroup$

Say I save variables x, y, z using Save["stuff.dat", {x, y, z}]. Is there any way, when using Get["stuff.dat"], that I can see what are the names of the variables being restored?

$\endgroup$
  • $\begingroup$ You could use $NewSymbol to track if Get[...] defines any new symbols, but this won't tell you if an already existing symbol gets overwritten. $\endgroup$ – JEM_Mosig Feb 16 '18 at 1:23
4
$\begingroup$

You could use TracePrint:

a=2;
b=3;
c[x_]:=x^2

Save["tst.m", {a,b,c}];

TracePrint[
    Get["tst.m"],
    _Set | _SetDelayed
]

a=2

b=3

c[x_]:=x^2

Addendum

If you just want to see the variables, you can add a custom TraceAction:

TracePrint[
    Get["tst.m"],
    _Set | _SetDelayed,
    TraceAction->(Print[Extract[#, {1, 1}, HoldForm]]&)
]

a

b

c[x_]

$\endgroup$
  • $\begingroup$ Will this work at the mx level though? I thought I remembered that preempting all my tricks $\endgroup$ – b3m2a1 Feb 16 '18 at 3:01
  • $\begingroup$ Thank you both for your help, but some of the variables I am restoring contain large amounts of data and these methods list every value along with the name. I don't need to know the values, just the variable names that have been restored. Is there a way to just list the variable names restored, but not their values? $\endgroup$ – Paul R. Feb 17 '18 at 2:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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