On 6/20/06, Matt Small <msmall@...> wrote:
> I'm not sure if it's possible, unfortunately. I'm going to look into
> updating stringmap, which I believe is a Jython construct, but I don't
> know of a way to change the Java Map & List types.
stringmap is org.python.core.PyStringMap -- it is not actually a dict
-- and it isn't really supposed to be (I believe). I think in an
earlier email you where concerned about the following Jython behavior:
>>> class a(object):
... pass
...
>>> a.__dict__
{'__dict__': <attribute '__dict__' of 'a' objects>, '__module__': '__main__'}
>>> type(a.__dict__)
<type 'stringmap'>
>>>
but, if you look at PEP 252 (which I am re-reading to get hints on
__slots__) You find this:
1. The __dict__ attribute on regular objects
A regular object may have a __dict__ attribute. If it does,
this should be a mapping (not necessarily a dictionary)
supporting at least __getitem__(), keys(), and has_key(). This
gives the dynamic attributes of the object. The keys in the
mapping give attribute names, and the corresponding values give
their values.
It does look like stringmap is missing __getitem__() -- though in
Jython internals it looks like we generally use __finditem__() for
this purpose... maybe I'll have to query Samuele or other Jython
old-timers about the __getitem__/__finditem__ thing....
> I wonder if there's a way to wrap the appropriate Python type around the
> Java object; something like:
>
> >>> import java.util.HashMap
> >>> a=java.util.HashMap()
> >>> d=dict(a)
This is something we should consider. We can already pass a
java.io.InputStream to file()
It shouldn't be too hard to implement a similar conversion by passing
a java.util.Map to dict(), a java.util.List to list() and a
java.util.Set to set()
-Frank
|