Just FYI, cstjean has implemented a really cool new feature in PyCall
(https://github.com/stevengj/PyCall.jl/pull/250 ... requires PyCall master
at the moment): you can now define new Python classes easily from Julia,
via a natural syntax:
@pyimport numpy.polynomial as P
@pydef type Doubler <: P.Polynomial
__init__(self, x=10) = (self[:x] = x)
my_method(self, arg1=5) = arg1 + 20 # the right-hand-side is Julia code
x2.get(self) = self[:x] * 2
x2.set!(self, new_x::Int) = (self[:x] = new_x / 2)
end
Doubler()[:x2]
is equivalent to the Python code:
class Doubler(numpy.polynomial.Polynomial):
def __init__(self, x=10):
self.x = x
def my_method(self, arg1):
return arg1 + 20
@property
def x2(self): return self.x * 2
@x2.setter
def x2(self, new_val):
self.x = new_val / 2
Multiple inheritance, special methods like __init__, and getter/setter
properties are all supported. Better yet, the methods support full Julian
multiple dispatch, optional args, and keywords (because, at their core,
they are ordinary Julia functions with ordinary dispatch taking place after
the Python arguments are converted to Julia types).
It will be interesting to see what new kinds of interoperability this
enables. (I suspect that Python GUI toolkits, which often require you to
define your own classes, will become much easier to use.)