Module aliasing in Julia

筅森魡賤 提交于 2020-01-24 02:23:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!