Unitful parse



Say I have 1m in a text file. I read the text file and put that “1m” into variable x. How do I parse this x so that it contains the Unitful.jl 1m?

julia> x = strip(readstring("a.txt")) # a.txt contains: 1m

julia> @u_str("$x")
ERROR: MethodError: no method matching parse(::Expr)


This works on 0.5, but relies on eval which is considered bad afaik.

julia> x = "1m"

julia> expr = quote @u_str($x) end
quote  # REPL[2], line 1:
    @u_str "1m"

julia> using Unitful

julia> a = eval(expr)
1 m


It worked in 0.6 too! Thanks!