# How to export parameters in a text file?

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

a=1;
b=2;
c=3;


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?

• I think Save is all you need, or did I miss something? – Kuba Apr 17 '19 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?

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

• According to the documentation for Save[] from Mathematica 12, the suggested way of importing the saved data is Get[] instead of Import[]. Indeed, Import gives an error. – Andrey R Jul 3 at 9:35
• I checked the code with MMA 12.1.1.0. Import works. With Get you don't have to use the post fix ToExpression. However, Import is great for importing other things such as URLs, Excel files etc. – FredrikD Jul 3 at 9:44