Import Julia module with different name

Viewed 168

In Python, you can import a module with whatever name you want by using the as keyword. Is there an equivalent to this in Julia?

Obviously you can just do

import moduleWithReallyLongName
M = moduleWithReallyLongName

Is there a better way?

1 Answers
import moduleWithReallyLongName
const M = moduleWithReallyLongName

Please note the usage of const. By a rule of thumb any global variable in Julia should be type stable, otherwise you will observe reduced performance.

Another option is the package ImportMacros.jl (https://github.com/fredrikekre/ImportMacros.jl)

using ImportMacros
@import moduleWithReallyLongName as M
Related