Unitful parse

question

#1

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
"1m"

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

#2

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

julia> x = "1m"
"1m"

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

julia> using Unitful

julia> a = eval(expr)
1 m

#3

It worked in 0.6 too! Thanks!