Jlwrap in PyJulia

Hi there,

I have successfully installed PyJulia on Mac, and it seems to work smoothly. I wrote a data reader in Julia, and it can be correctly called from Python. The REPL in Python showed

<PyCall.jlwrap Main.VisAna.Data{Float32}(Float32[-127.5; -126.5; ......

However, when I tried to manipulate on the returned arrays from Julia function calls in Python, it showed me

data[1]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: 'PyCall.jlwrap' object is not subscriptable

I saw some relevant discussions in PyCall issues, but got confused again.

My goal is to provide Python users a way to use data read from functions written in Julia. Is there an easy solution for me?

If you are OK with writing Python code and want to provide a Pythonic interface, the best option would be to create a Python class that wraps jlwrap. You can then call Julia functions inside the dunder methods like __getitem__. Look at how I did it in PyBase.jl as mentioned in the discussion you linked. Otherwise, you can also wait for https://github.com/JuliaPy/PyCall.jl/issues/617.

This is nice! Is there a way to use PyBase directly now? Say I am using Python 3.7 REPL. Now I understand why it doesn’t work before, but implementing a full Python class that wraps jlwrap object is a little bit excessive for me…

You can install it via pkg> add https://github.com/tkf/PyBase.jl (type ] in Julia REPL to get pkg> prompt). I haven’t tested it for a while so there may be a few trouble, though. If you want to fix some issues if any, use dev instead of add.