Java calls python to pass array parameters

pyList is an array

maven

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

The first and second parameters are the ymd character date

The third and fourth parameters are float

The fifth is float array

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);

The corresponding Python method is

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

Guess you like

Origin blog.csdn.net/zjy660358/article/details/126099875