Evaluate string as variable

In python,
a = 3
eval(“a”) equals 3

Any Julia method similar to “eval()”? Thanks.

1 Like

The closest correspondence is
eval(Meta.parse("a"))
but this is a case where the literal translation from Python is almost never the right thing to do in Julia.

What is the right approach depends on what you want to accomplish on a higher level.

6 Likes

See also: Metaprogramming · The Julia Language

2 Likes