I have some parameters defined in my notebook as, for example,


and I want to export these parameters to a .txt file in which I have the following text "a=1 b=2 c=3"

It doesn't matter the format I just want to have the structure "name=value". I found some information in google but none of them solved my problem. Do you know how to do it?

  • 3
    $\begingroup$ I think Save is all you need, or did I miss something? $\endgroup$ – Kuba Apr 17 at 10:58

As Kuba said, you can use save to put the parameters in a text file.

a = 1; b = 2; c = 3

Save[NotebookDirectory[] <> "parameters.txt", {a, b, c}]

Then test this through Clearing the values

Clear[a, b, c]

What does the txt file look like?

enter image description here

Then import and use ToExpression

Import[NotebookDirectory[] <> "parameters.txt"] // ToExpression; 

Check the values of a, b and c

{a, b, c}

(* 1, 2, 3*)

In case you/other users want to change the parameters to influence the computations, I find that using Google Spreadsheet or Excel better than text files (more structure, easier for other users).

If the parameters relate to states internal to your system, I prefer to use .wdx files


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.