ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

New WINDEV and WEBDEV 27 feature!
Help / WLanguage / WLanguage functions / Standard functions / Windows management functions / 
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Executes a function present in a Python module.
Example
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
// 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()
Syntax
<Result> = PythonExecute(<Module> , <Function> [, <Parameter 1> [... [, <Parameter N>]]])
<Result>: Variant
Value returned by the executed Python function (possibly empty).
<Module>: Character string
Name of the Python module to be loaded. See the Python documentation for more details.
Caution: The name of the module is "case-sensitive".
<Function>: Character string
Name of the Python function to be executed. This function can be found in <Module>.
Caution: The name of the function is "case-sensitive".
<Parameter 1>: Type of parameter
First parameter to be passed to the Python function.
<Parameter N>: Type of parameter
Last parameter to be passed to the Python function.
Remarks
  • The Python interpreter must have been configured beforehand (via PythonInitialize).
  • Only the following simple types can be used for the return value and for the different parameters of the Python function:
    • Boolean
    • Integer (signed or unsigned)
    • Real
    • Character string.
  • The Python module must be in the runtime directory. Otherwise, use PythonAddPath to specify the paths to be taken into account.
  • An error message is displayed in the following cases: interpreter not loaded, incorrect parameter type, etc.
  • When PythonExecute is called,
    • the strings passed as arguments are encoded in UTF-8.
    • the string returned by a function from the module in a variant is not automatically decoded. You must use UTF8ToString.
Related Examples:
WD Python Training (WINDEV): WD Python
[ + ] This example shows how to run Python code in WINDEV applications.
Prerequisite: Python 3 must be installed on the computer. To get Python 3, go to http://legacy.python.org/download/
Business / UI classification: Neutral code
Component: wd270vm.dll
Minimum version required
  • Version 27
This page is also available for…
Comments
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 May 2024
IMPORTANTE
IF PythonInitialize("C:\Programs\Python\Python39\python39.dll") THEN
PythonAddPath("C:\tmp\python-modules\")
PythonExecute("test_module", "id", 5)
END
Boller
13 May 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 May 2024

Last update: 06/08/2022

Send a report | Local help