|
|
|
|
|
- Presentación
- Atención
- Ejemplos de código
WLanguage permite el uso de funciones Python en modo nativo (para obtener más información, consulte Python: Llamadas nativas). También es posible ejecutar funciones Python a través de funciones WLanguage. Hay varias funciones disponibles:
Atención - Los módulos ".py" deben estar en el disco, en la carpeta del ejecutable implementado, o en la ubicación especificada con la función PythonAddPath. Los módulos ".py" no se pueden encontrar si están integrados en la biblioteca del ejecutable.
- Python distingue entre mayúsculas y minúsculas. Los nombres de los módulos y de las funciones deben escribirse respetando las mayúsculas y minúsculas.
Ejemplo 1:
PythonInitialize(PYTHON_INSTALL_PATH + "\Python39\python3.dll")
PythonAddPath("D:\source.test\pythonProject\venv\Lib\site-packages")
PythonAddPath("D:\source.test\pythonProject")
sEquation is string = "5*x**3+x**2-3*x+2"
sListRoot is string = PythonExecute("main", "solver", sEquation)
nNbRoot is int = StringCount(sListRoot, ",") + 1
Trace("The ""[%sEquation%]"" equation admits [%nNbRoot%] roots:")
FOR n = 1 _TO_ nNbRoot
Trace("r[%n%] = [%ExtractString(sListRoot, n, "", "")%]")
END
Ejemplo 2:
sPythonModule is string
<IF ExecutionTarget=Windows>
sPythonModule = SysDir(srLocalAppData) + ..
[fSep]+"Programs\Python\Python39\python39.dll"
<ELSE>
<IF ExecutionTarget=Linux>
sPythonModule ="/usr/bin/python/python39.so"
<END>
<END>
IF NOT PythonInitialize(sPythonModule) THEN
Error("Python initialization error", ErrorInfo())
RETURN
END
Info(HelloWorldImportedPythonFunction())
IF NOT PythonAddPath(fDataDir()) THEN
Error("Unable to initialize Python path", ErrorInfo())
RETURN
END
Info(PythonExecute("python_file", "HelloWorldPythonFunctionNotImported"))
PythonTerminate()
Esta página también está disponible para…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|