Hi everyone, I am interested to make a package available for python users. I understood that the right tool would be PyJulia. The point is, as I understand it has some limitations about the comprehension of valid identifiers right? Like methods such as sum!
because of the !
character which have to be replaced by sum_b
. But I am curious about the definition of parametric types. I guess we have a similar problem when dealing with the characters {}
right? Does it exist an alternative to deal with parametric types? Or maybe I am totally misunderstanding the aim of PyJulia?
I have a better experience with PythonCall / JuliaCall. But from the perspective of those questions I think they are the same.
If you want to instantiate these from Python, I think you probably just need to eval a string, e.g. ComplexInt = Main.eval("Complex{Int}")
. (Your Python wrapper package could always predefine a few such symbols for commonly used types.)
Indeed, unfortunately JuliaCall does not help on that point!
Yes, with either PyJulia or JuliaCall, you will need to use Main.eval
(or Main.seval
in the case of JuliaCall) as stevengj says to access any syntax not made available directly in the library. If you need to pass values, you can create a function and call that, e.g.
curly = Main.eval("(a,b...) -> a{b...}")
ComplexInt = curly(Main.Complex, Main.Int)
To access fields whose names are not valid Python identifiers, you can always use getattr
, such as getattr(Main, "+")
or getattr(Main, "push!")
. The _b
suffix (which JuliaCall has copied) is simply a convenience a very common case.
In JuliaCall, you can access the curly syntax for parametric types via ordinary indexing, just like for parametric type annotations in Python:
from juliacall import Main as jl
jl.Vector[jl.Int] # Vector{Int}
jl.NTuple[3, jl.String] # NTuple{3, String}
Indeed the curly
function is quiet convenient! Thanks a lot