# How to output the name of a tuple?

**URL:** <https://discourse.julialang.org/t/how-to-output-the-name-of-a-tuple/14901>\
**Category:** General Usage\
**Created:** [September 13, 2018, 9:28am UTC](https://discourse.julialang.org/t/how-to-output-the-name-of-a-tuple/14901 "2018-09-13T09:28:20Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![LeoK987](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leok987/32/4880_2.png) [@LeoK987](https://discourse.julialang.org/u/LeoK987)\
**Post date:** [September 13, 2018, 9:28am UTC](https://discourse.julialang.org/t/how-to-output-the-name-of-a-tuple/14901/1 "2018-09-13T09:28:20Z")

</div>

```julia
julia> aTuple = (1,2,3,4)
(1, 2, 3, 4)

julia> string(aTuple)
"(1, 2, 3, 4)"

julia> println(aTuple)
(1, 2, 3, 4)

```

How can I just get the name “aTuple”, instead of its content?

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [September 13, 2018, 9:42am UTC](https://discourse.julialang.org/t/how-to-output-the-name-of-a-tuple/14901/2 "2018-09-13T09:42:15Z")

</div>

“aTuple” is not the name of the tuple. Its a variable named “aTuple” which holds as a value a tuple.

As far as I know, there is no “easy” way to output the name of a variable as a string.  
You may look at

> <https://stackoverflow.com/questions/32928524/julia-introspection-get-name-of-variable-passed-to-function>

for some ideas on how to achieve that anyways.

And maybe this  
[https://docs.julialang.org/en/v1/manual/functions/#Tuples-1](https://docs.julialang.org/en/v1/manual/functions/#Tuples-1)  
is worth a reading for general information about “named tuples”.

---

<div class="post-metadata">

**Author:** ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)\
**Post date:** [September 13, 2018, 9:55am UTC](https://discourse.julialang.org/t/how-to-output-the-name-of-a-tuple/14901/3 "2018-09-13T09:55:29Z")

</div>

Maybe you want something like a named tuple?  
In Julia 1.0:

```nohighlight
named_tuple = (aTuple = (1,2,3,4),)
julia> named_tuple.aTuple
(1, 2, 3, 4)
julia> keys(named_tuple)[1]
:aTuple

```

---

<div class="post-metadata">

**Author:** ![korsbo](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/korsbo/32/15942_2.png) [@korsbo](https://discourse.julialang.org/u/korsbo)\
**Post date:** [September 13, 2018, 10:30am UTC](https://discourse.julialang.org/t/how-to-output-the-name-of-a-tuple/14901/4 "2018-09-13T10:30:28Z")

</div>

Macros can do this.

```julia
macro getname(name)
    return "$name"
end

mytuple = (1., 2.)
@getname(mytuple)

```

returns the string

```julia
"mytuple"

```

---

<div class="post-metadata">

**Author:** ![LeoK987](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leok987/32/4880_2.png) [@LeoK987](https://discourse.julialang.org/u/LeoK987)\
**Post date:** [September 13, 2018, 11:48am UTC](https://discourse.julialang.org/t/how-to-output-the-name-of-a-tuple/14901/5 "2018-09-13T11:48:12Z")

</div>

Thanks to all. NamedTuple seems a better fit.

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [September 13, 2018, 12:21pm UTC](https://discourse.julialang.org/t/how-to-output-the-name-of-a-tuple/14901/6 "2018-09-13T12:21:17Z")

</div>

What is wrong with `"aTuple"`?

---

<div class="post-metadata">

**Author:** ![LeoK987](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/leok987/32/4880_2.png) [@LeoK987](https://discourse.julialang.org/u/LeoK987)\
**Post date:** [September 13, 2018, 12:34pm UTC](https://discourse.julialang.org/t/how-to-output-the-name-of-a-tuple/14901/7 "2018-09-13T12:34:08Z")

</div>

I was looping through a bunch of tuples and the names were not handy. Now NamedTuple solves the problem easily.
