# Is there a possibility to pass data between two modules?

**URL:** <https://discourse.julialang.org/t/is-there-a-possibility-to-pass-data-between-two-modules/15621>\
**Category:** General Usage\
**Tags:** question\
**Created:** [September 28, 2018, 3:35pm UTC](https://discourse.julialang.org/t/is-there-a-possibility-to-pass-data-between-two-modules/15621 "2018-09-28T15:35:48Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheOnlyArtz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theonlyartz/32/12685_2.png) [@TheOnlyArtz](https://discourse.julialang.org/u/TheOnlyArtz)\
**Post date:** [September 28, 2018, 3:35pm UTC](https://discourse.julialang.org/t/is-there-a-possibility-to-pass-data-between-two-modules/15621/1 "2018-09-28T15:35:48Z")

</div>

Is there a possibility to pass data between two modules ?  
I got to modules with structs in them  
I want to pass data from module1 to module2

````julia
module moduleOne
 # how would I get the data from moduleTwo?
end

module moduleTwo
  struct dataTwo
    test::String  
  end
end```
````

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [September 28, 2018, 3:55pm UTC](https://discourse.julialang.org/t/is-there-a-possibility-to-pass-data-between-two-modules/15621/2 "2018-09-28T15:55:38Z")

</div>

```julia
module moduleTwo
  struct dataTwo
    test::String  
  end
end

module moduleOne
    import Main.moduleTwo: dataTwo
    a = dataTwo("hey")
    @show a
end

```

---

<div class="post-metadata">

**Author:** ![TheOnlyArtz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theonlyartz/32/12685_2.png) [@TheOnlyArtz](https://discourse.julialang.org/u/TheOnlyArtz)\
**Post date:** [September 28, 2018, 4:04pm UTC](https://discourse.julialang.org/t/is-there-a-possibility-to-pass-data-between-two-modules/15621/4 "2018-09-28T16:04:35Z")

</div>

But let’s say I have a function in moduleTwo (The module I want to get data from)

```julia
module moduleOne

  # How would I get the structure from moduleTwo? the one I create in the init function

end

module moduleTwo
  struct Self
    token::String
  end

  function init(token::String)
    structure = Self(token)
    connect(structure) # a function to connect the client to a websocket, unnecessary for now 
  end
end
```

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [September 28, 2018, 4:24pm UTC](https://discourse.julialang.org/t/is-there-a-possibility-to-pass-data-between-two-modules/15621/5 "2018-09-28T16:24:37Z")

</div>

You can have a global binding in `moduleTwo` and import that name in `moduleOne`. However, `moduleOne` definition should come later, I think.

---

<div class="post-metadata">

**Author:** ![TheOnlyArtz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theonlyartz/32/12685_2.png) [@TheOnlyArtz](https://discourse.julialang.org/u/TheOnlyArtz)\
**Post date:** [September 28, 2018, 4:25pm UTC](https://discourse.julialang.org/t/is-there-a-possibility-to-pass-data-between-two-modules/15621/6 "2018-09-28T16:25:03Z")

</div>

Can you please write an example (in code)

---

<div class="post-metadata">

**Author:** ![tomaklutfu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tomaklutfu/32/2411_2.png) [@tomaklutfu](https://discourse.julialang.org/u/tomaklutfu)\
**Post date:** [September 28, 2018, 4:30pm UTC](https://discourse.julialang.org/t/is-there-a-possibility-to-pass-data-between-two-modules/15621/7 "2018-09-28T16:30:43Z")

</div>

I didn’t test I am on a mobile phone but something like

```julia
module moduleTwo
  struct Self
    token::String
  end
  
  function init(token::String)
    global structure = Self(token)
    connect(structure) # a function to connect the client to a websocket, unnecessary for now 
  end
end

module moduleOne
import Main.moduleTwo: structure
#use structure
end

```

---

<div class="post-metadata">

**Author:** ![TheOnlyArtz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/theonlyartz/32/12685_2.png) [@TheOnlyArtz](https://discourse.julialang.org/u/TheOnlyArtz)\
**Post date:** [September 28, 2018, 4:33pm UTC](https://discourse.julialang.org/t/is-there-a-possibility-to-pass-data-between-two-modules/15621/8 "2018-09-28T16:33:56Z")

</div>

Seems like it did the job, thank you very much 🙂

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [September 28, 2018, 8:33pm UTC](https://discourse.julialang.org/t/is-there-a-possibility-to-pass-data-between-two-modules/15621/9 "2018-09-28T20:33:09Z")

</div>

Just pass the information as the argument to a function.
