How about simply iterating over the dict?
for (key, value) in dict
set(simulation, key, value)
end
Note, that you can actually access a type like this:
type T
a::Int
end
x = T(1)
x.(:a) = 10 #<- :a is a symbol, which can be created like this
symbol("string")
x.(:a) is equivalent to getfield(a, :a)
For function calls, tshort has the answers ;)
Besides you can do stuff like:
func(values(dict)...)
if you want to call a function with the values from the dict, which is a
little problematic due to the order.
Am Mittwoch, 11. Februar 2015 21:25:22 UTC+1 schrieb David P. Sanders:
>
> Hi,
>
> If I have a dictionary
>
> params = {"N": 10, "M": 2.0}
>
> how can I use it to define two variables N and M with the corresponding
> values?
>
> This sounds like it should be easy and obvious, say using `eval`?
> E.g. extract the keys and values into strings and then use
>
> eval(parse("N=10"))
>
> Is this reasonable?
>
> The use case is to load input parameters for a simulation. Maybe there is
> a better way?
>
> Thanks,
> David.
>