Java 调用python 传数组参数

pyList 即是数组

maven

 <dependency>
            <groupId>org.python</groupId>
            <artifactId>jython-standalone</artifactId>
            <version>2.7.0</version>
        </dependency>

第一个第二个参数是ymd字符日期

第三第四个参数是 float

第五个是float数组

PythonInterpreter interpreter = new PythonInterpreter();
        interpreter.execfile(Start.class.getClassLoader().getResource("temperature.py").getPath());

        PyFunction pyFunction = interpreter.get("temperature", PyFunction.class);



        PyObject[] data = {Py.newFloat(23.69),Py.newFloat(23.69),Py.newFloat(23.69),Py.newFloat(23.69),Py.newFloat(23.69)};
        PyList pyList = new PyList(data);
        PyObject[] pyObjects ={Py.newString("2022-06-12 12:18:11"),Py.newString("2022-06-12 23:59:54"),new PyFloat(21.57),new PyFloat(79.92),pyList};


        PyObject pyObj = pyFunction.__call__(pyObjects);
        System.out.println("the answer is: " + pyObj);

对应的Python方法为

def temperature(start_time, finish_time, min_temp, max_temp, data=[]):

猜你喜欢

转载自blog.csdn.net/zjy660358/article/details/126099875
今日推荐