Java llama a python para pasar parámetros de matriz

pyList es una matriz

experto

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

El primer y segundo parámetro son la fecha del carácter ymd

Los parámetros tercero y cuarto son flotantes.

El quinto es una matriz flotante.

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

El método Python correspondiente es

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

Supongo que te gusta

Origin blog.csdn.net/zjy660358/article/details/126099875
Recomendado
Clasificación