On Fri, Apr 25, 2008 at 9:03 PM, Jeff Emanuel <jemanuel@frii.com> wrote:
That's correct, unfortunately PyDictionary does not
implement java.util.Map.

You need to copy the dictionary to a Java map before
passing it to Java code.

def dictToJavaMap(dict):
 import java
 javaMap =java.util.HashMap()
 for i in dict.items():
 return javaMap

Hi Jeff,
          I used the method above to convert the Dictionary to a Map. When the method returns a javaMap , I am collecting it using a PyObject (within my java code).Therefore I have to convert it to a Map.At that moment it gives a class cast exception. Is there an alternative way of doing this correctly?

        PythonInterpreter interp = new PythonInterpreter();
        interp.exec("import sys");
        interp.exec("print sys.path");

        String str3 = "/home/heshan/workspace/IdeaProjects/PYtest/src/essentialScripts/myfile.py";
        PyObject obj = interp.eval("getDictionary()");

        String str4 = "dictToJavaMap(" + obj + ")";
        PyObject obj2 = interp.eval(str4);

        //String str = "" + obj + "[].get('operationName')";

        Map map = (Map) obj2;  
The above line gives a exception like below
Exception in thread "main" java.lang.ClassCastException: org.python.core.PyJavaInstance cannot be cast to java.util.Map
        Iterator k = map.keySet().iterator();
        while (k.hasNext()) {
            String key = (String) k.next();
            System.out.println("Key " + key + "; Value " +
                    (String) map.get(key));

Thanx in advance
Heshan Suriyaarachchi