PythonInvokeModule(ModuleId,FunctionName,Param,…)
ModuleId. Identifier of the unit containing a function.
FunctionName. Function name.
Param1, Param2, …, ParamN. Function parameter.
NOTE. To define the parameter, specify either the number or the address of the cell where it is located.
It returns the result of function stored in the Python unit.
NOTE. Before using the Python functions, make sure that integration between Python and Foresight Analytics Platform is executed.
The function can contain several parameters. New formulas are added automatically in the formula wizard after the user puts the cursor into the field with parameter. If extra parameters are added, they should be left empty. If the function contains no parameters, leave the Param field empty.
Keep in mind the following when calling a Python function:
Module name and function name are case-sensitive. Module name is specified without the .py extension.
The module where function is located must be copied to the Foresight Analytics Platform installation folder or must be imported to the Python library.
Parameters of the function and returned result must have one of the following data types: Null, Boolean, Integer, Double, Decimal (applied only to the result returned by the function), String.
If input and output operations are used in the module, then use the mechanism of critical sections for them.
TIP. For details on writing Python functions and on import of modules into the Python library, see Python documentation.
Consider the Python code contained in the Python module with the MOD_PYT identifier:
def calculate(a, b)
return b%a+a
def check(value)
if (value>1000):
return 1
else
return 0
The table contains examples of formulas using the PythonInvokeModule function:
| Formula | Result | Description |
| =PythonInvokeModule("MOD_PYT", "calculate", 4, 40) | 4 | The calculate function call from the Python module in the repository with the MOD_PYT identifier. Fixed values are sent as values of parameters. |
| =PythonInvokeModule("MOD_PYT", "check", C3) | 1 OR 0 | The check function call from Python module in the repository with the MOD_PYT identifier. The value of the C3 cell is sent as the parameter value. If the cell value is greater than 1000, 1 is returned, otherwise - 0. |
See also: