# Write access to a variable in a module

**URL:** <https://discourse.julialang.org/t/write-access-to-a-variable-in-a-module/59025>\
**Category:** General Usage\
**Created:** [April 11, 2021, 9:03am UTC](https://discourse.julialang.org/t/write-access-to-a-variable-in-a-module/59025 "2021-04-11T09:03:35Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![Eben60](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/eben60/32/13475_2.png) [@Eben60](https://discourse.julialang.org/u/Eben60)\
**Post date:** [April 17, 2021, 11:16am UTC](https://discourse.julialang.org/t/write-access-to-a-variable-in-a-module/59025/6 "2021-04-17T11:16:27Z")

</div>

Still one more way to get a write access through encapsulation is using structs:

```julia

module Md2

Base.@kwdef mutable struct State
    b1::Bool = false
    b2::Bool = false
end

const st = State()
export st
end

using .Md2

```

```julia

julia> st.b1
false
julia> st.b1=true;
julia> st.b1
true

```

I personally would prefer this one from the point of view of readability, especially if the module contains more than one state variable.

---

_[View the full topic](https://discourse.julialang.org/t/write-access-to-a-variable-in-a-module/59025)._
