I try to create and cast an object in Jython and I get the following error:
Exception in thread "MainThread" java.lang.ClassCastException: org.python.core.PySingleton cannot be cast to resources.ixia.IxNetType at resources.ixia.IxNetFactory.create(IxNetFactory.java:34) at resources.ixia.IxiaTest.run(IxiaTest.java:34) at resources.ixia.IxiaTest.<init>(IxiaTest.java:14) at resources.ixia.IxiaTest.main(IxiaTest.java:42)
Here is the code:
import org.python.core.PyObject; import org.python.util.PythonInterpreter; public class IxNetFactory { private PyObject ixNetClass; private PythonInterpreter interpreter; public IxNetFactory(String script_dir) { script_dir=script_dir.replace("\\", "/"); interpreter = new PythonInterpreter(); interpreter.exec("import sys"); interpreter.exec("sys.path.append('"+script_dir+"')"); interpreter.exec("import time"); interpreter.exec("import os"); interpreter.exec("from ixnetworks import IxNet");
In life, I cannot understand what I am doing wrong. Of all the things I read, I seem to be doing it right, but I can't get it to work.
If anyone who has experience with Jython can tell me what I'm doing wrong, that would be very appreciated.
source share