Search code examples
pythonelixiraritybeam

Using Elixir, erlport with Python 2.7.9, receiving an arity error


I am trying to use Python with Elixir and I wrote the following functional code (you can find the repo I'm building here: https://github.com/arthurcolle/elixir_with_erlport)

defmodule Snake do
  use Application

  def start(_type, _args) do
    import Supervisor.Spec, warn: false

    children = [
      # Define workers and child supervisors to be supervised
      # worker(Snake.Worker, [arg1, arg2, arg3]),
    ]

    opts = [strategy: :one_for_one, name: Snake.Supervisor]
    Supervisor.start_link(children, opts)
  end

  def py do
    {:ok, pp} = :python.start()
    :python.call(pp, :__builtin__, :print, ["hey there"])
  end
end

I can run iex -S mix run, then type in Snake.py, and I will get this output:

"hey there" :undefined

Okay, great.

Then I try to make it print out the current version of Python by swapping out the two lines above with:

{:ok, pp} = :python.start() :python.call(pp, :sys, :version, [])

But when I run it, it gives me this arity error

** (FunctionClauseError) no function clause matching in :erlport.call/5 src/erlport.erl:87: :erlport.call(#PID<0.108.0>, :sys, 'version.__str__', [], [])

Which doesn't make any sense to me because my call only is a :erlport.call/4, with one single list at the end (not 2 as it is saying).


Solution

  • {:ok, pp} = :python.start_link()
    :python.call(pp, :sys, String.to_atom("version.__str__"), [])