Erlport: Instantiation of python class and calling methods on the object

Hello everybody,
so I played with erlport and it works well for me on a module base (calling functions).
I tried to instanciate a custom python class to get an object, but I cannot call any methods on this object later.
I am not sure, if a completely understand how erlport works in the background, so maybe it not possible to “hold” the instance in erlang and later call methods on this instance.
Does anybody know if this should work with erlport? Some hint would be welcome.

Basically what I do is this:


class Pyclass:

def __init__(self):
    print("pyClass __init__")
    self.value = 3

def get_value(self):
    return self.value


   {ok, Python} = python:start_link([{python_path, "/path/"}, {python, "python3"}]),
   {'$erlport.opaque', python, Object} = python:call(Python, pyclass, 'Pyclass', []),
   python:call(Python, pyclass, 'Pyclass.get_value', [Object]).

what I get when running the code:
"'bytes' object has no attribute 'value'"

so self does not represent my python object, that’s for sure

Thanks, alex

What is it if you print it out (or repr it on the python side)?

1 Like

Hi, OvermindDL1,

printed out Object in erlang:
self in python:

some binary
I think I have to encode/decode, but I have no clue how to do that.
Unfortunately in the examples I have seen so far, only static methods are called, so maybe this is not working.

1 Like

Hmm, I’m unsure, might need to ask on their issue tracker, the docs seem to imply that should work…

I found the answer in a lfe lib called py, they use some extra python encoders/decoders for this (besides other things).
I could not get it to work, so I created pythra which uses their extra python modules and has the relevant lfe code translated to erlang.


1 Like

Wait what? An lfe library? Lisp Flavoured Erlang is awesome!

Oh yes it is, I did not really had a hard time reading it, although seen for the first time.
I translated the code mainly because I could not make it work for me and I do not want the extra lfe code.

1 Like