Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Not easy to explain what I'm looking for, so please sorry if I'm not so short.

Having many variables to be managed in several different combinations, I need to automate the assignment of preset values for those variables. So, I have some saved preset data to be assigned to variables but because this is very frequent in my source code, I want to make it automatically, without to name variables in each piece of code. So I would use a variable to keep the whole list of variables. Export is very easy, the problem is for Import. Here is an example:

vars = {"a", "b", "c", "d", "e", "f", "g", "h"};
Export["data.csv", Transpose[{vars, ToExpression[vars]}]]

I have to use the strings to list the variables otherwise the names will be replaced by variables' values before to export. And I have to save also the name of variables because files have to be exported to other software and be human readable. So the problem is when I have to import back the saved data. Normally I should write

{a, b, c, d, e, f, g, h} = Import["data.csv"][[All, 2]]

but (here is the problem) I would write

ToEpxression[vars] = Import["data.csv"][[All, 2]]

so to have assignments in just one line and without naming all variables in each piece of code. Of course, ToExpression[vars] doesn't work because it automatically replaces variables names with their values. So, my question: Is there a combination of Hold, Unevaluated, Defer, or similar constructs so to automatically create the list $\{a, b, c, d, e\}$ (unevaluated) as left-hand site of the Set statement.

Sorry for not being more clear and thanks in advance.

share|improve this question
A first raw solution: because I have to re-assign the variables, I can surely delete their previous values before to load the preset file. So I use Map[Clear, vars] and the Evaluate[ToExpression[vars]] = Import["data.csv"][[All,2]] – bobknight Dec 10 '13 at 20:26
Take a look here but in your case I would just make double export, to csv and with DumpSave or Save in order to get them back easily. – Kuba Dec 10 '13 at 20:26
Also, for an easy start you may ClearAll all variables before assigning – belisarius has settled Dec 10 '13 at 20:28
@Kuba, thanks for the idea od DumpSave, it could be the right choice in many cases. – bobknight Dec 10 '13 at 20:31
If @MrWizard is online he will see this and answer. This sort of problem has been canvassed a bit here although i do not have ready references handy. Mr Wizard has posted some useful code for this. So this question is undoubtedly a duplicate but I do not have links to previous questions handy. – Mike Honeychurch Dec 10 '13 at 20:59

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.