# How to print the names of symbols defined in modules?

**URL:** https://discourse.julialang.org/t/how-to-print-the-names-of-symbols-defined-in-modules/122714
**Category:** New to Julia
**Tags:** question
**Created:** [November 16, 2024, 11:28am UTC](https://discourse.julialang.org/t/how-to-print-the-names-of-symbols-defined-in-modules/122714 "2024-11-16T11:28:45Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![world-peace](https://avatars.discourse-cdn.com/v4/letter/w/9f8e36/32.png) [@world-peace](https://discourse.julialang.org/u/world-peace)
#### Post date: [November 16, 2024, 11:28am UTC](https://discourse.julialang.org/t/how-to-print-the-names-of-symbols-defined-in-modules/122714/1 "2024-11-16T11:28:45Z")

</div>

The names of symbols defined in the `Main` module can be printed using

```julia
julia> names(Main)
8-element Vector{Symbol}:
 :Base
 :Core
 :Main
 :SRC
 :TopLevelModule
 :skipInit
 :updateLoadPath

```

However the same trick cannot be used to print the names of the modules which are submodules of `Main`.

```julia
names(Main.TopLevelModule)
1-element Vector{Symbol}:
 :TopLevelModule

```

This is despite the fact that there are submodules defined inside `TopLevelModule`.

```julia
julia> TopLevelModule.NestedModule.nestedModuleFunction()
nestedModuleFunction

```

Is the `names` function the right way to print the names of modules and other symbols defined inside the `Main` module?

If so, why does this not work for further submodules?

---

<div class="post-metadata">

### Author: ![sgaure](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sgaure/32/14779_2.png) [@sgaure](https://discourse.julialang.org/u/sgaure)
#### Post date: [November 16, 2024, 11:44am UTC](https://discourse.julialang.org/t/how-to-print-the-names-of-symbols-defined-in-modules/122714/2 "2024-11-16T11:44:24Z")

</div>

I can’t reproduce this. It works fine for me.

```julia
julia> module Foo
       const foo = 1
       const bar = 2
       public foo
       end
Main.Foo

julia> names(Main.Foo)
2-element Vector{Symbol}:
 :Foo
 :foo

```

(version 1.11.1)
