# Setting Variables from a Parameters Text File

**URL:** <https://discourse.julialang.org/t/setting-variables-from-a-parameters-text-file/26946>\
**Category:** General Usage\
**Created:** [July 29, 2019, 3:23pm UTC](https://discourse.julialang.org/t/setting-variables-from-a-parameters-text-file/26946 "2019-07-29T15:23:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dburch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dburch/32/8741_2.png) [@dburch](https://discourse.julialang.org/u/dburch)\
**Post date:** [July 29, 2019, 3:23pm UTC](https://discourse.julialang.org/t/setting-variables-from-a-parameters-text-file/26946/1 "2019-07-29T15:23:24Z")

</div>

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**.

> **name,type,value**  
> var1,Int64,44  
> var2,Float64,1.5  
> var3,String,Hello World

I want to use this file to dynamically create variables in Julia.

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [July 29, 2019, 3:57pm UTC](https://discourse.julialang.org/t/setting-variables-from-a-parameters-text-file/26946/2 "2019-07-29T15:57:49Z")

</div>

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;`

Then

```julia
julia> @eval $vName = $vType($vValue);

julia> var1

11.0

```

---

<div class="post-metadata">

**Author:** ![dburch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dburch/32/8741_2.png) [@dburch](https://discourse.julialang.org/u/dburch)\
**Post date:** [July 29, 2019, 8:19pm UTC](https://discourse.julialang.org/t/setting-variables-from-a-parameters-text-file/26946/3 "2019-07-29T20:19:44Z")

</div>

Thank you! I was not aware of the @eval function.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [July 29, 2019, 8:28pm UTC](https://discourse.julialang.org/t/setting-variables-from-a-parameters-text-file/26946/4 "2019-07-29T20:28:20Z")

</div>

Note that this is only possible in global scope.

---

<div class="post-metadata">

**Author:** ![dburch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dburch/32/8741_2.png) [@dburch](https://discourse.julialang.org/u/dburch)\
**Post date:** [July 29, 2019, 8:51pm UTC](https://discourse.julialang.org/t/setting-variables-from-a-parameters-text-file/26946/5 "2019-07-29T20:51:48Z")

</div>

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);`.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 29, 2019, 9:24pm UTC](https://discourse.julialang.org/t/setting-variables-from-a-parameters-text-file/26946/6 "2019-07-29T21:24:10Z")

</div>

> [@dburch](#):
>
> I have a file populated with **variable name** , **variable type** , and **variable value**.

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.
