|
From: <bc...@wo...> - 2001-11-17 23:36:00
|
[Fred Sells on jython-users. I moved it to jython-dev because my reply
concern the development of jython]
>I'm using the python function call
>
>foo(**settings) to allow any options to be set in the call.
>
>foo then calls javabar(settings) where
>
>public void javabar(PyDictionary dictionary)
There is no garantee that the **setting object is a PyDictionary. It can
also be a PyStringMap or a PyInstance.
>I would like to convert dictionary to a Hashtable without stepping through
>all the elements. Is there a way?
Not at the moment, but first I want to make sure I understand your
request correctly. From java you want to something like:
PyObject o = ... // Assigned from some python code.
Hashtable h = Py.py2hashtable(o);
If we decide to add a method like Py.py2hashtable(..), what should it
do? Here is my take (completely untested):
public static Hashtable py2hashtable(PyObject o) {
Hashtable htable = new Hashtable();
Class Class = Object.class;
PyObject keys = o.invoke("keys");
int len = key.__len__();
for (int i = 0; i < len; i++) {
PyObject key = keys.__finditem__(i);
PyObject value = o.__finditem__(key);
htable.put(Py.tojava(key, oClass),
Py.tojava(value, oClass));
}
return htable;
}
regards,
finn
|