python - Maple Help

type/python

check for an object of type python

 Calling Sequence type(x, python)

Parameters

 x - any expression

Description

 • The call type(x, python) checks to see if x is of type python. It returns true if x is of type python, and false otherwise.
 An object is of type python if it is a reference to an object from a Python session running alongside the current Maple session.
 • Such objects may be created with commands from the Python package such as EvalFunction, EvalMember, EvalString, or GetVariable.
 • The convert/python function can convert expressions in Maple into type python expressions which reference equivalent Python expressions.
 • The following convert routines can convert expressions of type python to equivalent Maple expressions.

Examples

Construct a Python set and check that it is of type python.

 > $s≔\mathrm{Python}:-\mathrm{EvalString}\left("set\left(\left[3,5,7\right]\right)"\right)$
 ${s}{≔}{""}$ (1)
 > $\mathrm{type}\left(s,\mathrm{python}\right)$
 ${\mathrm{true}}$ (2)

Construct a Python list. Since conversion to Maple lists is automatic, the default result will not be of type python.

 > $L≔\mathrm{Python}:-\mathrm{EvalString}\left("\left[1,3,5,5,8\right]"\right)$
 ${L}{≔}\left[{1}{,}{3}{,}{5}{,}{5}{,}{8}\right]$ (3)
 > $\mathrm{type}\left(L,\mathrm{python}\right)$
 ${\mathrm{false}}$ (4)

If a Python object is explicitly requested, the result will be of type python.

 > $L≔\mathrm{Python}:-\mathrm{EvalString}\left("\left[1,3,5,5,8\right]",\mathrm{output}=\mathrm{python}\right)$
 ${L}{≔}{""}$ (5)
 > $\mathrm{type}\left(L,\mathrm{python}\right)$
 ${\mathrm{true}}$ (6)

The convert command can also construct Python expressions.

 > $M≔\mathrm{Matrix}\left(\left[\left[0.0357116785741896,0.959492426392903\right],\left[0.655740699156587,0.792207329559554\right]\right],\mathrm{datatype}=\mathrm{float}\left[8\right]\right)$
 ${M}{≔}\left[\begin{array}{cc}{0.0357116785741896}& {0.959492426392903}\\ {0.655740699156587}& {0.792207329559554}\end{array}\right]$ (7)
 > $\mathrm{type}\left(M,\mathrm{python}\right)$
 ${\mathrm{false}}$ (8)
 > $\mathrm{PM}≔\mathrm{convert}\left(M,\mathrm{python}\right)$
 ${\mathrm{PM}}{≔}{""}$ (9)
 > $\mathrm{type}\left(\mathrm{PM},\mathrm{python}\right)$
 ${\mathrm{true}}$ (10)

Compatibility

 • The type/python command was introduced in Maple 2020.
 • For more information on Maple 2020 changes, see Updates in Maple 2020.