|
|
|
|
|
- Overview
- Caution
- Code samples
WLanguage supports Python functions in native mode (for more details, see Python: Native calls). You can also execute Python functions via WLanguage functions. Several functions are available:
| | PythonAddPath | Adds the path of a directory or the path of the virtual environment to search for Python modules. | PythonExecute | Executes a function present in a Python module. | PythonInitialize | Specifies the location of the Python DLL to be loaded. | PythonTerminate | Unloads the Python DLL and frees memory. |
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.
Example 1:
PythonInitialize(PYTHON_INSTALL_PATH + "\Python39\python3.dll")
PythonAddPath("D:\source.test\pythonProject\venv\Lib\site-packages")
PythonAddPath("D:\source.test\pythonProject")
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
Example 2:
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
Error("Python initialization error", ErrorInfo())
RETURN
END
Info(HelloWorldImportedPythonFunction())
IF NOT PythonAddPath(fDataDir()) THEN
Error("Unable to initialize Python path", ErrorInfo())
RETURN
END
Info(PythonExecute("python_file", "HelloWorldPythonFunctionNotImported"))
PythonTerminate()
Related Examples:
|
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/
|
This page is also available for…
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|