ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Standard functions / Windows functions / Python functions
  • Overview
  • How to proceed?
  • Importing the ".py" file
  • Using Python functions in WLanguage code
  • Caution
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Overview
WLanguage allows for native Python calls.
The principle is simple:
  1. Import the ".py" file into the WINDEV project.
  2. In the WLanguage code:
    • Load the Python DLL.
    • Call Python functions.
Note: You can also execute Python functions directly from WLanguage. For more details, see Python: Using WLanguage.
How to proceed?

Importing the ".py" file

Importing the ".py" file into the environment allows for the automatic recognition of all the functions of the ".py" script. Each script function is then considered a native WLanguage function..
To import the ".py" file:
  1. Set up a Python interpreter. This interpreter will read the information contained in the ".py" file.
    • On the "Home" tab, in the "Environment" group, expand "Options" and select "WINDEV/WEBDEV general options".
    • Go to the "Directories" tab and enter the path of the interpreter (python*.dll file) in "Python interpreter".
      Note: This Python version may be different from the one used at runtime.. However, it must be compatible with Python 3.9, the reference Python ABI used in WINDEV and WEBDEV. The Python interpreter must be the same architecture as WINDEV or WEBDEV (32 or 64-bit).
    • Validate the configuration window.
  2. Import the ".py" files via the "Project explorer" pane using one of the following methods:
    • Open the context menu of "External descriptions" and select "Import a Python module into this project". Select the file that corresponds to the module and validate.
      Note: It is possible to import all Python modules in a directory using the "Import all Python modules in a directory into this project" option.
    • Open the context menu of "Other" and select "Add elements". Select the file that corresponds to the module and validate.
    • Drag the ".py" file from the Windows explorer and drop it onto the "Project explorer" pane.
  3. The Python file is in the project folder, and the module (with its functions) will appear in the "Project explorer" pane, in the "External descriptions" folder.
Remark: When developing the application, it is also necessary to indicate the path of the Python libraries used in the current project configuration:
  1. In the "Project Explorer" pane, display the context menu for the "Configurations" option and select "Description".
  2. On the "Components" tab, specify the external Python libraries.

Using Python functions in WLanguage code

To use Python functions in WLanguage code:
  1. Initialize the Python engine using PythonInitialize. This function defines the Python interpreter used for the execution. You can use an interpreter different from the one used for the import, but it must be compatible with Python ABI 3.9.
  2. Enter the name of the Python function to execute, with its parameters if necessary.
    Please note: not all parameter passing types are supported.. The default values of the parameters are not taken into account. Parameters are passed by value only. In addition, only the following types can be used to pass parameters, and for the return value:
    • Boolean,
    • Integer (signed or unsigned),
    • Real,
    • Character string.

Caution

  • The ".py" modules must be accessible on disk, in the folder of the deployed executable, or in the location specified with PythonAddPath. The ".py" modules cannot be found if they are embedded in the executable library.
  • Python is case-sensitive. The module and function names must be written using correct upper and lower case characters.
Minimum version required
  • Version 27
This page is also available for…
Comments
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: 10/08/2024

Send a report | Local help