AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Ayuda / WLanguage / Funciones WLanguage / Funciones estándar / Funciones de Windows / Funciones Python
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
Ejecuta una función de un módulo de Python.
Ejemplo
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. Debe utilizar la función UTF8ToString.
Clasificación Lógica de negocio / UI: Código neutro
Componente: wd300vm.dll
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
IF PythonInitialize("C:\Programs\Python\Python39\python39.dll") THEN
PythonAddPath("C:\tmp\python-modules\")
PythonExecute("test_module", "id", 5)
END
Boller
13 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