Hi all,
I have a file named functions.jl
which I import into a Pluto notebook using
include("scripts/functions.jl")
.
I want to list all the function names in the functions file, what is the best practice to do it?
Thank you !
Hi all,
I have a file named functions.jl
which I import into a Pluto notebook using
include("scripts/functions.jl")
.
I want to list all the function names in the functions file, what is the best practice to do it?
Thank you !
Files do not correspond to an organisational structure in Julia and is purely up to the programmer.
Put the functions into a module, e.g. like
module MyFunctions
include("scripts/functions.jl")
end
using .MyFunctions
then you can query like MyFunctions.<autocomplete shows possible functions>
.
Just written like this, you accessing the functions requires the full qualification with the module’s name. Use export functionname
to remove the need for qualification.
Thank you, just so I can completely understand, the snippet you show goes into the notebook right? and Then whenever I use one of the functions from the file I need to type MyFunctions.<function name>
?
Yes that’s one way.
Preferrably you’d make the file itself a module:
In scripts/functions.jl
:
module MyFunctions
# export foo, bar # optionally export some names
...
end
In the notebook:
begin
include("scripts/functions.jl")
using .MyFuncions
end
Then you can:
MyFunctions.<Tab>
MyFunctions.notexported()
Great answer! Thank you so much!