Reputation: 6865
I am to use Jython to import two supposedly identical java files for comparison. The comparison is made on the basis of returned values, signatures, and constructors (This works fine, though the problem is in the import). One file resides in the submission
folder and the other in the solution
folder. The problem is the following,
When I run the following code,
sys.path.append('Solution/')
import GeometricShape
sys.path.pop()
sys.path.append('Submission/')
import GeometricShape <---- the imported module is the same as the one above
sys.path.pop()
the second imported GeometricShape is of the one in the solution
folder, whereas it should be of the submission
folder. Deleting the module by del(sys.modules["GeometricShape"])
would still keep the first GeometricShape
in memory somehow. imp.load_source
doesn't work because it is not a python source file. Creating __init__
in the directories and importing the modules as from Solution import GeometricShapes
doesn't work, for I get the error below,
java.lang.NoClassDefFoundError: Solution/GeometricShape (wrong name: GeometricShape)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at org.python.core.SyspathJavaLoader.findClass(SyspathJavaLoader.java:123)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.python.core.Py.loadAndInitClass(Py.java:909)
at org.python.core.Py.findClassInternal(Py.java:844)
at org.python.core.Py.findClassEx(Py.java:895)
at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:133)
at org.python.core.packagecache.PackageManager.findClass(PackageManager.java:28)
at org.python.core.packagecache.SysPackageManager.findClass(SysPackageManager.java:122)
at org.python.core.PyJavaPackage.__findattr_ex__(PyJavaPackage.java:137)
at org.python.core.PyObject.__findattr__(PyObject.java:863)
at org.python.core.packagecache.PackageManager.lookupName(PackageManager.java:136)
at org.python.core.PyModule.impAttr(PyModule.java:106)
at org.python.core.imp.import_next(imp.java:720)
at org.python.core.imp.ensureFromList(imp.java:888)
at org.python.core.imp.ensureFromList(imp.java:856)
at org.python.core.imp.import_module_level(imp.java:850)
at org.python.core.imp.importName(imp.java:917)
at org.python.core.ImportFunction.__call__(__builtin__.java:1220)
at org.python.core.PyObject.__call__(PyObject.java:357)
at org.python.core.__builtin__.__import__(__builtin__.java:1173)
at org.python.core.imp.importFromAs(imp.java:1011)
at org.python.core.imp.importFrom(imp.java:987)
at org.python.pycode._pyx2.get_solution$4(D:\Grader\autograder.py:48)
at org.python.pycode._pyx2.call_function(D:\Grader\autograder.py)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyBaseCode.call(PyBaseCode.java:120)
at org.python.core.PyFunction.__call__(PyFunction.java:307)
at org.python.pycode._pyx2.main$9(D:\Grader\autograder.py:158)
at org.python.pycode._pyx2.call_function(D:\Grader\autograder.py)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyBaseCode.call(PyBaseCode.java:120)
at org.python.core.PyFunction.__call__(PyFunction.java:307)
at org.python.pycode._pyx2.f$0(D:\Grader\autograder.py:159)
at org.python.pycode._pyx2.call_function(D:\Grader\autograder.py)
at org.python.core.PyTableCode.call(PyTableCode.java:165)
at org.python.core.PyCode.call(PyCode.java:18)
at org.python.core.Py.runCode(Py.java:1275)
at org.python.util.PythonInterpreter.execfile(PythonInterpreter.java:235)
at org.python.util.jython.run(jython.java:247)
at org.python.util.jython.main(jython.java:129)
Is there a solution to this?
Upvotes: 0
Views: 142