Reputation: 704
I find using Module
in julia is equivalent to from Module import *
in python. Is there any way to import a single function or variable from a module.
Upvotes: 1
Views: 299
Reputation: 2699
You can import e.g. a single function with
using Module.func
If you also want to be able to extend the function with new methods, use instead
import Module.func
If you want to import several named functions and variables from the same module, you can e.g. use one of
using Module: func1, func2
import Module: func1, func2
All of these forms allow to import definitions from Module
regardless of whether they are exported there, unlike using Module
, which only imports exported definitions.
Also keep in mind that it is really values that are imported, not variables, so if you try to assign to an imported variable, you will not see a change in the originating module (and you will get a warning).
Upvotes: 5
Reputation: 1843
If you have a module Foo
with a function bar
(or something else specific you wan to import) you can do:
import Foo: bar
This brings only bar
into scope.
Upvotes: 1