As I understand, PyCall documentation says that it supports dot-access to Python object attributes:
Given o::PyObject
, o.attribute
in Julia is equivalent to o.attribute
in Python, with automatic type conversion.
However, even a very simple example of that fails:
using PyCall
@pyimport matplotlib.pyplot as plt
plt.gca().set_aspect("equal") # ERROR: type PyObject has no field set_aspect
plt.gca()[:set_aspect]("equal") # works
Do I misunderstand something in how Julia and/or PyCall work?
You need to be on the PyCall master branch for this feature, none of the tagged releases have this yet. Try running add PyCall#master
from the package prompt.
1 Like
Elaborating a bit more, when you navigate to a package’s github repository you see the current master branch by default. This includes the README.md
. On master, dot access is possible as in python. I made a big PR for that which got merged some time ago. However, there are a couple of things left to do before this makes a new consistent release. Hence a new PyCall version hasn’t been tagged yet.
As @marius311 mentioned, you can use add PyCall#master
to checkout the bleeding edge version of PyCall to try out the dot access feature already.
1 Like
In fact, turns out @stevengj released a new PyCall 1.9 version two days ago: Releases · JuliaPy/PyCall.jl · GitHub
So, no need for checking out #master
anymore.
3 Likes
Thank you for pointing at version difference, didn’t notice that. Indeed, I had an older version than 1.9.