names
names(x::Module[, all=false[, imported=false]])
Get an array of the names exported by a Module
, with optionally more Module
globals according to the additional parameters.
Examples
-
Get the names of exported functions in a module:
julia> module MyModule export foo, bar, baz function foo() println("This is foo") end function bar() println("This is bar") end function baz() println("This is baz") end end julia> names(MyModule) 3-element Array{Symbol,1}: :bar :baz :foo
This example returns an array of symbols representing the names of the functions exported by the module
MyModule
. -
Get all names in a module, including imported names:
julia> using LinearAlgebra julia> names(Main, all=true) 4-element Array{Symbol,1}: :LinearAlgebra :Main :MyModule :Sys
Here,
names
is used to retrieve all names in theMain
module, including imported modules likeLinearAlgebra
. -
Get only the imported names in a module:
julia> using Statistics julia> names(Main, all=false, imported=true) 1-element Array{Symbol,1}: :Statistics
In this example,
names
is used to fetch only the imported module names in theMain
module.
Common mistake example:
julia> module MyModule
export foo, bar, baz
function foo()
println("This is foo")
end
function bar()
println("This is bar")
end
function baz()
println("This is baz")
end
end
julia> names(MyModule, all=true)
ERROR: MethodError: no method matching names(::Module, ::Bool)
In this example, the names
function is mistakenly used with the all
parameter on a module. The all
parameter is applicable only when used with the Main
module.
See Also
User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.