Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jython塔架映射到列表<;字符串>;以及其他Jython到Java变量的映射_Java_Python_List_Jython - Fatal编程技术网

Jython塔架映射到列表<;字符串>;以及其他Jython到Java变量的映射

Jython塔架映射到列表<;字符串>;以及其他Jython到Java变量的映射,java,python,list,jython,Java,Python,List,Jython,如何迭代Jython PyList并将包含的对象转换为java.lang.String 在以前的教程中,它是通过使用_uu_u; tojava __;来完成的,比如: (EmployeeType)employeeObj.__tojava__(EmployeeType.class); 我支持这可能是这样的: PyList pywords = pythonFactoryCreatedObject.pythonMethodReturningPyList() int count = pyword

如何迭代Jython PyList并将包含的对象转换为java.lang.String

在以前的教程中,它是通过使用_uu_u; tojava __;来完成的,比如:

(EmployeeType)employeeObj.__tojava__(EmployeeType.class);
我支持这可能是这样的:

 PyList pywords = pythonFactoryCreatedObject.pythonMethodReturningPyList()

 int count = pywords.__len__();
 for (int idx = 0 ; idx < count ; idx++) {
     PyObject obj = pywords.__getitem__(idx);

    //here i do not know how to have a kind of 'String word = pywords[idx]' statement

    //System.out.println(word);
 }
PyList pywords=pythonFactoryCreatedObject.pythonMethodReturningPyList() int count=pywords.uu len_uuu(); for(int idx=0;idx 是否也可以有:

  • 从PyList到java数组或列表的转换?这样就可以使用“for(String word:mylist){}”构造了吗

  • 简单的python字典映射到适当的java对象也会遇到同样的问题,最好的映射是什么

有关于Jython的java部件用法的教程文档吗?我对python非常熟悉,但对Java和Jython还不熟悉,我只找到了Jython关于Java用法的文档,而我需要在Java框架中嵌入python模块


best

PyList
实际上实现了
java.util.List
,所以您可以直接从java端使用它。 如果用字符串填充,则其元素将是
PyString
(或者可能是
PyUnicode
)。 因此:

不管你觉得哪个更清楚

编辑:
. 从Java使用Jython的更好方法是从Jython实现Java接口并从Java操作接口,但您似乎正在使用现有的Python代码库,因此如果没有一些更改,这将无法工作。

感谢您的有用解释!我没有理解使用“toJava”的要点,你的回答帮助我更好地理解。
List pywords = pythonFactoryCreatedObject.pythonMethodReturningPyList();
for (Object o : pyList){
  String string = ((PyString) o).getString();
  //whatever you want to do with it 
}
List pywords = pythonFactoryCreatedObject.pythonMethodReturningPyList()
for (Object o : pyList){
  String string = ((PyObject) o).__toJava__(String.class);
  //whatever you want to do with it 
}