|
|
|
|
Ejecuta una función de un módulo de Python. sPythonModule is string <IF ExecutionTarget=Windows> // Example of a Python module location // The name of the Python module can be different sPythonModule = SysDir(srLocalAppData) + .. [fSep]+"Programs\Python\Python39\python39.dll" <ELSE> <IF ExecutionTarget=Linux> // Example of a Python module location // The name of the Python module can be different // (depends on the version of Python, the Linux distribution) sPythonModule ="/usr/bin/python/python39.so" <END> <END> IF NOT PythonInitialize(sPythonModule) THEN // In this case, you must: // Check the path // Check that the compilation mode (32/64-bit) matches the runtime mode Error("Python initialization error", ErrorInfo()) RETURN END Info(HelloWorldImportedPythonFunction()) // With an imported Python file (.py) in the project that contains: // def HelloWorldImportedPythonFunction(): // return "Hello World!"; IF NOT PythonAddPath(fDataDir()) THEN Error("Unable to initialize Python path", ErrorInfo()) RETURN END // "python_file.py" must be in the directory // specified by PythonAddPath. // In this example, this directory is the data directory Info(PythonExecute("python_file", "HelloWorldPythonFunctionNotImported")) PythonTerminate() Sintaxis
<Result> = PythonExecute(<Module> , <Function> [, <Parameter 1> [... [, <Parameter N>]]])
<Result>: Variant Valor devuelto por la función Python ejecutada (posiblemente vacío). <Module>: Cadena de caracteres Nombre del módulo de Python a cargar. Para obtener más información, consulte la documentación de Python. Atención: El nombre del módulo distingue entre mayúsculas y minúsculas. <Function>: Cadena de caracteres Nombre de la función Python a ejecutar. Esta función se encuentra en el módulo <Module>. Atención: El nombre de la función distingue entre mayúsculas y minúsculas. <Parameter 1>: Tipo de parámetro Primer parámetro a pasar a la función Python. <Parameter N>: Tipo de parámetro Último parámetro a pasar a la función Python. Observaciones - El intérprete de Python debe haber sido configurado previamente (con la función PythonInitialize).
- Solo se pueden utilizar los siguientes tipos simples para el valor de retorno y para los diferentes parámetros de la función Python:
- Boolean
- Integer (signed o unsigned)
- Real
- Character string.
- El módulo de Python debe estar en el directorio de ejecución. En caso contrario, utilice la función PythonAddPath para especificar las rutas que deben tenerse en cuenta.
- Un mensaje de error aparece en los siguientes casos: intérprete no cargado, tipo de parámetro incorrecto, etc.
- Cuando se llama a la función PythonExecute,
- las cadenas pasadas como argumentos están codificadas en UTF-8.
- la cadena devuelta por una función del módulo en una variable de tipo Variant no se descodifica automáticamente. Se debe utilizar la función UTF8ToString.
Clasificación Lógica de negocio / UI: Código neutro
Esta página también está disponible para…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|