|
From: Joseph C. <jca...@in...> - 2001-07-18 16:19:43
|
Samuele,
Originally you had:
import org.python.core.*;
import org.python.util.*;
public class Test {
public static void main(String[] args) {
PythonInterpreter interp = new PythonInterpreter();
interp.exec("class A:\n def m(self,a,b):\n print a,b");
PyClass A =(PyClass)interp.eval("A");
PyInstance a = (PyInstance)A.__call__();
PyObject m = A.__findattr__("m");
interp.exec("class A:\n def m(self,a,b):\n print b,a");
PyClass A2 =(PyClass)interp.eval("A");
PyInstance a2 = (PyInstance)A2.__call__();
PyObject m2 = A2.__findattr__("m");
m2.__call__(a2,new PyInteger(1),new PyInteger(2));
m.__call__(a,new PyInteger(1),new PyInteger(2));
}
}
Which I agree works just fine... however if you modify to look like the
following:
import org.python.core.*;
import org.python.util.*;
public class Test {
public static void main(String[] args) {
PythonInterpreter interp = new PythonInterpreter();
interp.exec("class A:\n def m(self,a,b):\n print a,b");
interp.exec("class B(A):\n def n(self,a,b):\n print a,b");
PyClass class =(PyClass)interp.eval("B");
PyInstance instance = (PyInstance)class.__call__();
PyObject obj = instance.__findattr__("n");
// This call works here.
obj.__call__(instance,new PyInteger(1),new PyInteger(2));
interp.exec("class A:\n def m(self,a,b):\n print a,b");
interp.exec("class B(A):\n def n(self,a,b):\n print a,b");
// This call doesn't work here.
obj.__call__(instance,new PyInteger(1),new PyInteger(2));
}
}
You should get the Trace telling you you have to call the unbound method with
an instance first argument.
--
"Every new beginning comes from some other beginnings
end."
-- Semisonic
-----------------------------------------------------
Joseph Campbell | EMAIL: joe...@in...
Staff Consultant | URL: www.inventa.com
Inventa Technologies | PH: (856)914-5224
| CELL: (609)972-0297
-----------------------------------------------------
|