How to print the names of symbols defined in modules?

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

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.

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

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

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?

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

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)

1 Like