Brian

Brian

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

Showing Posts 1 to 10

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.

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 #2
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().

m31271n

m31271n

  • import_file/1
  • c/1 / c/2 / r/1

Above are what you need. Enjoy!

robchristian

robchristian

Wow, not a single one of of these worked for me. Many show the module compile, but then the functions I expect are undefined. Could somebody show me a complete example, of how to run Jason.encode!(%{ "a" => 1 }), in the Elixir REPL, from inside a mix project?

hauleth

hauleth

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

axelson

Scenic Core Team

Generally in Elixir you will not be importing modules from outside your project, so you will not need the techniques listed in this post. Instead you will generally declare dependencies (by adding to the list of deps in your mix.exs file). Then (as @hauleth showed) you can run iex -S mix to start an iex session inside the project, which will have all the modules from all your dependencies loaded (also if you’re using phoenix you may be interested in running iex -S mix phx.start to have an iex shell in the same beam instance as your phoenix application).

Here’s a page from the official tutorial with some more info: https://elixir-lang.org/getting-started/mix-otp/introduction-to-mix.html

fargozhu

fargozhu

what if you need to debug in a docker prod container where you don’t have the mix* files and you need to load HTTPoison to understand a catchy issue that doesn’t happen in your test env?

axelson

axelson

Scenic Core Team

Yeah, that doesn’t sound like a general case :+1:

mrjbj

mrjbj

I have a fixture under test/support/fixtures that isn’t working. I was hoping to load that module into iex and debug it interactively but i get “module not loaded and could not be found”. Is there a way to config for this scenario? Thanks.

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews