Elixir has four ways to access functionality from other modules
This allows us to the short version especially for nested name spaces.
alias MyApp.Accounts.User let us use just
User rather than the full
It also allows us to define our own short names. e.g.
MyApp.LattitudeAndLongitude as latlong
python supports the second use case via
import module as shortname syntax
Import functionality from other modules. This is similar to python’s
from module import syntax.
In python, if you want to import a few functions, you use
from module import
func1, func2 etc. But if you want to use most but not all functions, you
end up with a long
except options to make such importing easier.
use adds the functionality from other modules into the current one.
1 2 3 4 5 6 7 8 9 10 11
defmodule Module2 do def func2 do IP.puts "func2" end end defmodule Module1 do use Module2 end Module1.func2
func2 became available to
python does not have similar functionality.
This is similar to
use except for macros. It makes a macro from an external
module available to the compiler at compile time.