Home | Sign in | English EN
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WindowsLinuxPHPWEBDEV - Browser code
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Stored procedures
Executes a function present in a Python module.
sPythonModule is string
<IF ExecutionTarget=Windows>
// Example of a Python module location
// The name of the Python module can be different
sPythonModule = SysDir(srLocalAppData) + ..
<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"
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())
// 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())
// "python_file.py" must be in the directory
// specified by PythonAddPath.
// In this example, this directory is the data directory
Info(PythonExécute("python_file", "HelloWorldPythonFunctionNotImported"))
<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.
  • 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 variable of type 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: wd280vm.dll
Minimum version required
  • Version 27
This page is also available for…
Click [Add] to post a comment