我有以下两个文件:
# script.exs
Code.eval_file("module.ex");
import MyModule # Doesn't work
my_function() # What I want
# module.ex
defmodule MyModule do
def my_function() do
IO.puts "My Function"
end
end
运行elixir script.exs
时,错误消息如下:
** (CompileError) script.exs:3: module MyModule is not loaded and could not be found
但是,如果您要编写MyModule.my_function()
,则代码可以正常运行。
那么,是否可以从动态加载的模块导入函数?