# How to initialize a unit with Unitful.jl when reading values and units from a file?

**URL:** https://discourse.julialang.org/t/how-to-initialize-a-unit-with-unitful-jl-when-reading-values-and-units-from-a-file/93978
**Category:** New to Julia
**Tags:** question, unitful
**Created:** [February 3, 2023, 9:38am UTC](https://discourse.julialang.org/t/how-to-initialize-a-unit-with-unitful-jl-when-reading-values-and-units-from-a-file/93978 "2023-02-03T09:38:16Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![RPS](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@RPS](https://discourse.julialang.org/u/RPS)
#### Post date: [February 3, 2023, 9:38am UTC](https://discourse.julialang.org/t/how-to-initialize-a-unit-with-unitful-jl-when-reading-values-and-units-from-a-file/93978/1 "2023-02-03T09:38:16Z")

</div>

Hello,  
I’m parsing a file defining values and corresponding units, for which I would like to initialize unitful variables in julia. Currently, it is not clear to me how to use the @u\_str macro, when the value and unit are themselves variables (e.g. the value is a Float64 and the unit is a represented by a string), e.g.:

```julia
value = 2.0
unit = "L"
unitful_variable = @u_str(...) # ???

```

---

<div class="post-metadata">

### Author: ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)
#### Post date: [February 3, 2023, 10:41am UTC](https://discourse.julialang.org/t/how-to-initialize-a-unit-with-unitful-jl-when-reading-values-and-units-from-a-file/93978/2 "2023-02-03T10:41:01Z")

</div>

You can use the `uparse` function for this:

```julia
value = 2.0
unit = "L"
unitful_variable = value * uparse(unit)

```

The `uparse` function is currently not mentioned in the package documentation, we should probably change that.

---

<div class="post-metadata">

### Author: ![RPS](https://avatars.discourse-cdn.com/v4/letter/r/9e8a1a/32.png) [@RPS](https://discourse.julialang.org/u/RPS)
#### Post date: [February 3, 2023, 2:27pm UTC](https://discourse.julialang.org/t/how-to-initialize-a-unit-with-unitful-jl-when-reading-values-and-units-from-a-file/93978/3 "2023-02-03T14:27:59Z")

</div>

Thanks a lot - I was not aware of the uparse functionality.
