Julia | Code loading (`include`, `using`, `import`)
Julia has several ways of loading code from other locations: include
, using
, and import
[1]:
include("path/to/file.jl") # evaluates the expressions in the target file in the current context
using some_package # adds all exported names in `some_package` to the current module's namespace
some_package_function_1() # all exported in `some_package` can now be used without prefix
some_package_function_2()
using some_package: some_package_function_1 # adds the specific name in `some_package` to the current namespace
some_package_function_1() # all exported in `some_package` can now be used without prefix
some_package_function_2() # invalid, since this function wasn't included in the `using` statement
import some_package # adds `some_package` itself to the current namespace, but doesn't directly add its exports
some_package.some_package_function_1() # names inside the package can be called through the package name
some_package_function_1() # invalid, since we used `import` instead of `using`
Resources: