Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A python "as" equivalent in julia

Tags:

using

julia

When I want to import a package in python, I can alias it:

import package_with_a_very_long_nameeeeee as pl

After that statement, I can refer to the package by it alias:

pl.foo()

julia allows me to do:

using PackageWithAVeryLongName
pl = PackageWithAVeryLongName
pl.foo()

But it feels like an ugly hack, possibly with implications I do not understand.

Is there an idiomatic way to alias imported packages in julia?

like image 269
NG_ Avatar asked Oct 28 '25 08:10

NG_


1 Answers

This is now possible on the upcoming Julia 1.6 using the exact same syntax as Python uses:

julia> import LinearAlgebra as LA

julia> typeof(LA)
Module

help?> LA.svd
  svd(A; full::Bool = false, alg::Algorithm = default_svd_alg(A)) -> SVD

On prior versions, you can do what @Bill suggests — but I'd strongly recommend doing so as a const assignment alongside an import:

julia> import SparseArrays

julia> const SA = SparseArrays
SparseArrays
like image 146
mbauman Avatar answered Oct 30 '25 11:10

mbauman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!