So, I read a set of variables and respective values from a file and store them in a variable
specs = {{"Type", "KP", "fp"}, {"LP1", 2, 2000}, {"Type", "KP", "fp", "Qp"}, {"LP2", 4, 1000, 3}}
Each pair of variables/specs shall be treated separately. Also depending on the file this fields might change both names and variables. This creates a problem because I basically lose the name of the variables.
I try to do
For[i = 1, i <= Length[specs], i = i + 2, Evaluate[ToExpression[specs[[i]]]]=specs[[i+1]] ];
And while the first iteration goes well, the second iteration gets me
Set::setraw: Cannot assign to raw object LP1. Set::setraw: Cannot assign to raw object 2. Set::setraw: Cannot assign to raw object 2000.
And of course that is because "Type", "KP", "fp" were assigned to "LP1", 2, 2000 in the first iteration and now can't be evaluated again. Any smart way to fix this? Again I can't specifically put on the code Clear[Type, KP, fP] as the variables might change their names in other files. This is supposed to be robust to that level.
Thank you.
{{Type -> "LP1", KP -> 2, fp -> 2000}, {Type -> "LP2", KP -> 4, fp -> 1000, Qp -> 3}}
$\endgroup$Transpose /@ Partition[specs, 2]
(generating lists) orThread@*Rule @@@ Partition[specs, 2]
(generating rules) orAssociation@*Thread@*Rule @@@ Partition[specs, 2]
(generating associations). $\endgroup$