问题
In python you can do something like this to let you use a shortened module name:
>>> import tensorflow as tf
From then on you can refer to tf
, instead of having to type tensorflow
everywhere.
Is something like this possible in Juila?
回答1:
Yep, you can just assign the module to a new name.
import JSON
const J = JSON
J.print(Dict("Hello, " => "World!"))
I highly recommend to use the const
because otherwise there will be a performance penalty. (With the const
, there is no performance penalty.)
回答2:
If you do this constantly and really like the familiar syntax maybe you should use the package ImportMacros, which enables the following:
julia> @import tensorflow as tf
Just install the package with
julia> using Pkg; Pkg.add("ImportMacros")
and add using ImportMacros
to your .juliarc.jl
to load the package at the start of every session automatically.
来源:https://stackoverflow.com/questions/42104130/module-aliasing-in-julia