Is it possible to do this and how would I do it?
I have a file populated with variable name, variable type, and variable value.
I want to use this file to dynamically create variables in Julia.
I am assuming that loading the data into variables is not an issue.
Let’s say we have loaded the equivalent of
vName = :var1; vType = :Float64; vValue = 11;
julia> @eval $vName = $vType($vValue);
Thank you! I was not aware of the @eval function.
Note that this is only possible in global scope.
That’s a good call. Thank you for clarifying. Fortunately, I plan to use this for setting constants at the global scope:
@eval const $vName = $vType($vValue);.
I would just use a standard format like JSON and read it into a dictionary with JSON.jl. Much more flexible that parsing your own format and calling
eval to define global variables.