AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Ayuda / WLanguage / Funciones WLanguage / Funciones estándar / Funciones de Windows / Funciones Python
  • Presentación
  • Atención
  • Ejemplos de código
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
Presentación
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:
PythonAddPathAgrega la ruta de un directorio o del entorno virtual para buscar módulos de Python.
PythonExecuteEjecuta una función de un módulo de Python.
PythonInitializeIndica la ubicación de la DLL de Python a cargar.
PythonTerminateDescarga la DLL de Python y libera la memoria.

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.
Ejemplos de código
Ejemplo 1:
// Initialize the Python interpreter
PythonInitialize(PYTHON_INSTALL_PATH + "\Python39\python3.dll")
// Declare the import paths of the modules used
PythonAddPath("D:\source.test\pythonProject\venv\Lib\site-packages")
PythonAddPath("D:\source.test\pythonProject")
// Solve 5x³+x²-3x+2=0
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>
	// 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()
Versión mínima requerida
  • Versión 27
Esta página también está disponible para…
Comentarios
IMPORTANTE
Hello Guys!

Para resolver a compilação do Python pelo Webdev voce tera que fazer o seguinte ajuste:

https://hostimage.windev.io/images/BUG64_c5a2a700bcd82b0dcceab7c195f4fad7.png

Na versao inglesa
C:\PCSOFT\WEBDEV 29\Programs\Engine

Na versão francesa
C:\PCSOFT\WEBDEV 29\Programmes\Moteur

Copiar tudo da pasta 64 e colar na pasta 32

C:\PCSOFT\WEBDEV 29\Programs\Engine\Win64x86
para
C:\PCSOFT\WEBDEV 29\Programs\Engine\Win32x86

Substituir tudo

Testar novamente o teu projeto Python vai funcionar.

Abri chamado informado do ocorrido quem sabe em futuras versoes isso esteja resolvido.

Por algum motivo o Python busca pela pasta 32 em vez de buscar pela pasta 64.

Espero ter ajudado.
Boller
25 05 2024
IMPORTANTE
PARA FUNCIONAR NO WEBDEV

É necessário setar corretamente o caminho do modulo python, para executar uma função em um módulo python:

sPythonModule is string

<IF ExecutionTarget=Windows>

sPythonModule = SysDir(srLocalAppData) + ..
[fSep]+"Programs\Python\Python39\python39.dll"

END
Boller
13 05 2024

Última modificación: 15/09/2024

Señalar un error o enviar una sugerencia | Ayuda local