Brian

Brian

Import a module from a file into IEX

What is the proper way to load a module from a file in to IEX?

In the python world, doing something like this pretty standard:

from . import xyz
xyz.do_something()

I did a bit of google and this is what I found
$ iex

Code.load_file(“some_file.exs”)
moduleFromSomeFile.doSomething(1)

I was wondering if this is the “right” way to import a module in to iex and just inspecting/playing around with functions.

Thank you

Most Liked

elderbas

elderbas

If I’m just dinkin around in a directory, outside of a mix project, and I have a module named “SomeModule.exs” in the working directory and I’m in iex, I do
c "SomeModule.exs", and I’ll have the module available to play with.

12
Post #3
OvermindDL1

OvermindDL1

If the compiled module is on the binary path for the BEAM then you can just do import Xyx to import everything from it. Or call it straight with Xyz.blah(42). mix sets up all those paths for you automatically if it is part of a project so with a mix project you can just do iex -S mix to get everything linked properly.

hauleth

hauleth

$ iex -S mix
iex> Jason.encode!(%{"a" => 1})
"{\"a\":1}"
bgargi

bgargi

Hey there!
You could simply use- “import abc” (Given that you are in the directory where the module is defined)
and then happily use the functions defined in abc ,and hence without having to do abc.fun1() simply do fun1().

ityonemo

ityonemo

Clarifying what @al2o3cr means into an actionable:

You probably actually want to run MIX_ENV=test iex -S mix to get that module.

Where Next?

Popular in Questions Top

srinivasu
How to handle excepions in elixir? Suppose i have A, B, C ,D, E modules. and each module has get() function. A.get() method will call th...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
Werner
Hi, I’m using Ubuntu 18.04 and after updating to OTP-24.0 yesterday i have this warning when I run “mix local.hex”: 14:57:30.512 [warn] ...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers' Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New

Other popular topics Top

joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 record...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
273 38985 115
New

We're in Beta

About us Mission Statement