pyget
pyget |
Purpose
Synopsis
procedure pyget(expr:string,var:array|set|list)
function pygetbool(expr:string):boolean
function pygetint(expr:string):integer
function pygetreal(expr:string):real
function pygetstr(expr:string):string
function pygettext(expr:string):text
Arguments
expr
|
Python expression to evaluate
|
var
|
Destination Mosel array, set or list
|
Example
The following example evaluates a Python dictionary expression and writes the result to a Mosel array. It then retrieves a real value from Python:
declarations Arr: dynamic array(set of integer) of real end-declarations pyexec("import math") Arr(0) := 0.1; Arr(1) := 1.1 ! Old array data reset(Arr) ! Clear old array data pyget("{1: math.pi, 2: math.e}", Arr) ! Add new data to array writeln("Arr: ", Arr) writeln("pi: ", pygetreal("math.pi"))
Further information
1. At first, the function interprets the expression as a global variable name and tries to access the variable by getting it from the attributes of the Python
__main__ module. If this fails, the expression is evaluated by Python and the result is written to or returned as a Mosel variable. It is a fatal error if the expression evaluation or the type conversion fails.
2. The first version of the
pyget routine is additive: it writes the new elements to the existing Mosel array, set or list without clearing previously existing elements. Use
reset to manually clear an array, set or list before calling this function.
3. See the I/O
Driver python Section for further details about type conversions. Use
pycall to call a single function with input arguments or return value.
4. Do not concatenate untrusted strings from the end user into the
expr string. See Section
Xpress Insight configuration for more information.
Related topics
Module
python3