Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import Julia module with different name

Tags:

julia

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?

like image 207
Yly Avatar asked Jan 01 '23 21:01

Yly


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
like image 161
Przemyslaw Szufel Avatar answered Feb 20 '23 11:02

Przemyslaw Szufel