2
$\begingroup$

I could not find any reasonable answer for the following question. (https://www.physicsforums.com/threads/mathematica-output-display.386890/).

I have expressions:

f1=1;
f2=20;

I want to save them in a single file:

PutAppend[f1,f2,"output.m"];

This prints all the expression in the output file. The output of this is:

cat output.m
1
20

However I was wondering is there any way to print (save) the variable name as well or any customised name. The desired output:

f1=1
f2=20

or

name1=1
name2=20

I tried some but those are not useful.

$\endgroup$
2
$\begingroup$
foo = {"test"};
bar = Association[];
Save["test.m", {foo, bar}]
FilePrint["test.m"]
foo = {"test"}

bar = <||>

You can Get the symbols back to the current namespace after you have restarted the Kernel or have just removed them once:

ClearAll["Global`*"]
foo
bar
Get["test.m"]
foo
bar
foo

bar

<||>

{"test"}

<||>
$\endgroup$
  • $\begingroup$ This helps. Save["output.m",f1,f2] will give the desired output, however without customization of the name at the time of printing/saving. Of course one can always change the expression name f1-> name1 and f2-> name2. $\endgroup$ – Boogeyman Sep 7 '18 at 16:04

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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