Python - Maple Programming Help

Home : Support : Online Help : Connectivity : Python : Python/EvalFunction

Python

 EvalFunction
 evaluate a Python function

 Calling Sequence EvalFunction(f,arg1,arg2,...) EvalFunction(f,arg1,arg2,...,output=mode )

Parameters

 f - string or Python object argN - (optional); arguments to the function call mode - (optional); identical(maple,python,none)

Description

 • The EvalFunction command executes a function, f(arg1,arg2,...) using the Python interpreter.
 • 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.
 • If you have a callable python object, f, you can use ordinary Maple function syntax to call it f(a,b,c).
 • This function is part of the Python package, so it can be used in the short form EvalFunction(..) only after executing the command with(Python). However, it can always be accessed through the long form of the command by using Python[EvalFunction](..).

Examples

 > $\mathrm{with}\left(\mathrm{Python}\right):$
 > $\mathrm{ImportModule}\left("math"\right)$
 > $\mathrm{EvalFunction}\left("math.sin",1.0\right)$
 ${0.841470984807897}$ (1)
 > $\mathrm{mathsin}≔\mathrm{EvalString}\left("math.sin"\right)$
 ${\mathrm{mathsin}}{≔}{">"}$ (2)
 > $\mathrm{mathsin}\left(1.0\right)$
 ${0.841470984807897}$ (3)
 > $r≔\mathrm{EvalFunction}\left("math.sin",1.0,'\mathrm{output}'='\mathrm{python}'\right)$
 ${r}{≔}{""}$ (4)
 > $\mathrm{EvalFunction}\left("abs",r\right)$
 ${0.841470984807897}$ (5)

Compatibility

 • The Python[EvalFunction] command was introduced in Maple 2018.