parse and evaluate a Python statement
(optional) zero or more options as specified below
output = one of maple,python, or none
Specifies the output the evaluation should produce.
By default the value returned is converted into a Maple data structure. If no conversion is available, the return value will be an expression of type python, a Python object reference that can be used in subsequent calls to Python.
To avoid Maple conversions of the return value and always get a Python object, use the option, output=python.
To avoid all conversions, and omit the return value, use the option, output=none.
The EvalString command sends the given string to be executed by a Python interpreter.
By default the given cmd is prepended with syntax to form a temporary variable assignment so that the result can be fetched and sent back to Maple as a reference or converted data structure. This is the default output=maple mode.
To avoid data-structure conversions use output=python. With this option, even trivial conversions like integer results will remain as Python object references. More typically this output mode is used for very large results that need to be passed to another Python function, but will not otherwise be used directly in Maple.
The output=none option is required for statements where it is syntactically invalid to be prefixed with a temporary variable assignment. This includes procedure declarations, import statements, and multi-line scripts among other things.
Evaluating Python commands is stateful. Variables assigned in previous commands remain assigned and can be used in subsequent commands until a Maple restart is executed.
This function is part of the Python package, so it can be used in the short form EvalString(..) only after executing the command with(Python). However, it can always be accessed through the long form of the command by using Python[EvalString](..).
A simple evaluation:
Remember ^ means bitwise XOR in Python:
Access something built in
EvalString⁡statistics.median_grouped([1, 3, 3, 5, 7], interval=2)
When defining a procedure make sure you use the output=none option
EvalString⁡def mysum(a,b): return a+b,output=none
Indentation matters; use \n for newlines and spaces or \t for tabs
return sum( ([x] if not isinstance(x, list) else flatten(x)
for x in lst),  ),output=none:
Multiple statements can be evaluated at the same time, but the result returned to Maple is from the FIRST statement, not the last.
It is recommended to use output=none when evaluating multiple statements at the same time
To avoid automatic data-structure conversion use output=python
emptystring ≔ EvalString⁡'',output=python
emptystring≔<Python object: >
The Python[EvalString] command was introduced in Maple 2018.
For more information on Maple 2018 changes, see Updates in Maple 2018.
Download Help Document