# Unitful parse

**URL:** https://discourse.julialang.org/t/unitful-parse/4573
**Category:** General Usage
**Tags:** question, unitful
**Created:** [June 30, 2017, 6:41pm UTC](https://discourse.julialang.org/t/unitful-parse/4573 "2017-06-30T18:41:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [June 30, 2017, 6:41pm UTC](https://discourse.julialang.org/t/unitful-parse/4573/1 "2017-06-30T18:41:16Z")

</div>

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
julia> x = strip(readstring("a.txt")) # a.txt contains: 1m
"1m"

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

```

---

<div class="post-metadata">

### Author: ![ggggggggg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggggggggg/32/265_2.png) [@ggggggggg](https://discourse.julialang.org/u/ggggggggg)
#### Post date: [June 30, 2017, 7:37pm UTC](https://discourse.julialang.org/t/unitful-parse/4573/2 "2017-06-30T19:37:09Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![yakir12](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yakir12/32/297_2.png) [@yakir12](https://discourse.julialang.org/u/yakir12)
#### Post date: [July 1, 2017, 6:28am UTC](https://discourse.julialang.org/t/unitful-parse/4573/3 "2017-07-01T06:28:39Z")

</div>

> [@ggggggggg](#):
>
> a = eval(expr)

It worked in 0.6 too! Thanks!
