From: Cliff H. <xl...@da...> - 2009-11-30 21:55:26
|
I'm curious, and without testing it out myself, I wonder if Jython "gracefully" handles the Java Collections of Sets and Maps, so that I can simply treat them as Python sets and dicts. What I mean is, if I was to write the following Java code: Set<String> test = new HashSet<String>(); And then using the JSR-223 interface, hand that object to a Jython script, could I use Python set semantics? The same for a map... if I was to make a map: Map<String,String> testMap = new HashMap<String,String>(); And do the same thing, could I use the standard semantics for dicts (like referring to elements by key, i.e.: testMap["Item A"]) It would be convenient if I could, but if not, I can work around it easily enough. -- "I'm not responcabel fer my computer's spleling errnors" - Xlorep DarkHelm Website: http://darkhelm.org Sent from Santa Maria, California, United States |
From: Carl T. <ctr...@gm...> - 2009-11-30 22:11:06
|
On 11/30/09, Cliff Hill <xl...@da...> wrote: > I'm curious, and without testing it out myself, I wonder if Jython > "gracefully" handles the Java Collections of Sets and Maps, so that I can > simply treat them as Python sets and dicts. > > What I mean is, if I was to write the following Java code: > > Set<String> test = new HashSet<String>(); > > And then using the JSR-223 interface, hand that object to a Jython script, > could I use Python set semantics? > > The same for a map... if I was to make a map: > > Map<String,String> testMap = new HashMap<String,String>(); > > And do the same thing, could I use the standard semantics for dicts (like > referring to elements by key, i.e.: testMap["Item A"]) > > It would be convenient if I could, but if not, I can work around it easily > enough. > > -- > "I'm not responcabel fer my computer's spleling errnors" - Xlorep DarkHelm > Website: http://darkhelm.org > Sent from Santa Maria, California, United States > I did something like this recently with jython 2.2. The HashSet<String> imported fine, but then it behaved like a Python list (took any object type as an object, printed out like a list). I did not try to add a duplicate element. Not sure what the most recent jython implementation does. Carl T. |
From: Hasan D. <has...@gm...> - 2009-12-01 03:15:01
|
2009/11/30 Cliff Hill <xl...@da...>: > I'm curious, and without testing it out myself, I wonder if Jython > "gracefully" handles the Java Collections of Sets and Maps, so that I can > simply treat them as Python sets and dicts. I didn't see anything when I looked through the jython source, so I've put up some code at http://hasandiwan.info for maps[1] and sets[2]. Hope it helps. -- Sent from my mobile device Envoyait de mon telephone mobil 1. http://hasandiwan.info/2009/11/how-to-view-java-maps-as-python-dictionaries.html 2. http://hasandiwan.info/2009/11/how-to-view-java-sets-as-pythons-sets.html |
From: Hasan D. <has...@gm...> - 2009-12-01 04:34:34
|
2009/11/30 Hasan Diwan <has...@gm...>: > I didn't see anything when I looked through the jython source. On second glance, it appears to work. My code, however, has a bug, throwing NoSuchElementException as soon as Iterator.hasNext() is False. Would appreciate help with the solution. Many thanks in advance. -- Sent from my mobile device Envoyait de mon telephone mobil |
From: Cliff H. <xl...@da...> - 2009-12-02 00:52:31
|
That actually is a bug I already reported to the Jython project. There apparently is some issues with Java Iterators in Jython 2.5.x it seems... On Mon, Nov 30, 2009 at 8:34 PM, Hasan Diwan <has...@gm...> wrote: > 2009/11/30 Hasan Diwan <has...@gm...>: > > I didn't see anything when I looked through the jython source. > > On second glance, it appears to work. My code, however, has a bug, > throwing NoSuchElementException as soon as Iterator.hasNext() is > False. Would appreciate help with the solution. Many thanks in > advance. > -- > Sent from my mobile device > Envoyait de mon telephone mobil > > > ------------------------------------------------------------------------------ > Join us December 9, 2009 for the Red Hat Virtual Experience, > a free event focused on virtualization and cloud computing. > Attend in-depth sessions from your desk. Your couch. Anywhere. > http://p.sf.net/sfu/redhat-sfdev2dev > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users > -- "I'm not responcabel fer my computer's spleling errnors" - Xlorep DarkHelm Website: http://darkhelm.org |