Java 实现PyObject';Jython中的dict查找方法:(uu finditem+;?)
我有一个扩展了Java 实现PyObject';Jython中的dict查找方法:(uu finditem+;?),java,jython,Java,Jython,我有一个扩展了PyObject的Java类,它包含一个Map,我想我应该在Jython中免费获得dict行为。相反,我得到了一个错误TypeError:myclassname对象不可订阅 看起来我必须至少实现该方法(参见第654-670行): 我该怎么做?是否有检查PyObject是否为字符串的示例?如果键不是字符串,会发生什么 我是否也必须覆盖\uuuuuuuuuuuuuuuuuuu (这与类似,但有一个相对简单的解决方案。) /** * Very similar to the standa
PyObject
的Java类,它包含一个Map
,我想我应该在Jython中免费获得dict
行为。相反,我得到了一个错误TypeError:
myclassname对象不可订阅
看起来我必须至少实现该方法(参见第654-670行):
我该怎么做?是否有检查PyObject
是否为字符串的示例?如果键不是字符串,会发生什么
我是否也必须覆盖\uuuuuuuuuuuuuuuuuuu
(这与类似,但有一个相对简单的解决方案。)
/**
* Very similar to the standard Python __getitem__ method.
* Instead of throwing a KeyError if the item isn't found,
* this just returns null.
*
* Classes that wish to implement __getitem__ should
* override this method instead (with the appropriate
* semantics.
*
* @param key the key to lookup in this container
*
* @return the value corresponding to key or null if key is not found
**/
public PyObject __finditem__(PyObject key) {
throw Py.TypeError(String.format("'%.200s' object is unsubscriptable",
getType().fastGetName()));
}