From: Jeff E. <jem...@fr...> - 2010-02-01 16:41:53
|
The Iterator returned by the Set returned by keySet() calls toJava on the PyObject in Iterator.next(). * PyMapSet serves as a wrapper around Set Objects returned by the java.util.Map interface of * PyDictionary. entrySet, values and keySet methods return this type for the java.util.Map * implementation. This class is necessary as a wrapper to convert PyObjects to java Objects for * methods that return values, and convert Objects to PyObjects for methods that take values. The * translation is necessary to provide java access to jython dictionary objects. This wrapper also * provides the expected backing functionality such that changes to the wrapper set or reflected in * PyDictionary. To get the unconverted PyObjects, you can call __iter__(). joh...@no... wrote: > > Hello, > > I’m making a call to a Python function that returns a dictionary > (string -> dictionary), i.e. > > a= {} > > a[‘blah’]= { ‘active’: True } > > The Java code seems a bit odd. Here’s the call to return the dict a: > > Map<PyObject,PyObject> status = > (Map<PyObject,PyObject>)f.__call__(params); > > And then I can iterate through the keys: > > Iterator i = status.keySet().iterator(); > > while (i.hasNext()) > > { > > String key = (String)i.next(); > > System.out.println("K "+key+" "+key.getClass()); > > I would expect K to be PyObject, but it’s String. I would expect to > write the Iterator as: > > Iterator<PyObject> i = status.keySet().iterator(); > > while (i.hasNext()) > > { > > PyObject key = (PyObject)i.next(); > > So, what’s Jython doing as it’s a little confusing! > > > John > > -- > > John Baker, > > JEE Architect, London Web Technology. > > > > This e-mail (including any attachments) is confidential, may contain > proprietary or privileged information and is intended for the named > recipient(s) only. Unintended recipients are prohibited from taking > action > on the basis of information in this e-mail and must delete all copies. > Nomura will not accept responsibility or liability for the accuracy or > completeness of, or the presence of any virus or disabling code in, this > e-mail. If verification is sought please request a hard copy. Any > reference > to the terms of executed transactions should be treated as preliminary > only > and subject to formal written confirmation by Nomura. Nomura reserves the > right to monitor e-mail communications through its networks (in > accordance > with applicable laws). No confidentiality or privilege is waived or > lost by > Nomura by any mistransmission of this e-mail. Any reference to > "Nomura" is > a reference to any entity in the Nomura Holdings, Inc. group. Please read > our Electronic Communications Legal Notice which forms part of this > e-mail: > http://www.Nomura.com/email_disclaimer.htm > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------------ > The Planet: dedicated and managed hosting, cloud storage, colocation > Stay online with enterprise data centers and the best network in the business > Choose flexible plans and management services without long-term contracts > Personal 24x7 support from experience hosting pros just a phone call away. > http://p.sf.net/sfu/theplanet-com > ------------------------------------------------------------------------ > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > |