Python - Maple Programming Help

Online Help

All Products    Maple    MapleSim


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

Python

  

DefineFunction

  

parse and evaluate a Python def statement

 

Calling Sequence

Parameters

Description

Examples

Compatibility

Calling Sequence

DefineFunction(def)

Parameters

def

-

string

Description

• 

The DefineFunction command sends the given string, def, to be executed by a Python interpreter.  

• 

This command is the same as calling Python:-EvalString with the output=none option.

• 

This command always returns NULL.  A subsequent EvalString or GetVariable command must be used if you want to get a reference to the procedure that was defined.

• 

This function is part of the Python package, so it can be used in the short form DefineFunction(..) only after executing the command with(Python). However, it can always be accessed through the long form of the command by using Python[DefineFunction](..).

Examples

withPython:

DefineFunctiondef mysum(a,b): return a+b

EvalStringmysum(1,2)

3

(1)

MySumGetVariablemysum

MySum<Python object: <function mysum at 0x7f9de4739710>>

(2)

MySum4&comma;5

9

(3)

Indentation matters; use \n for newlines and spaces or \t for tabs

DefineFunctiondef flatten(lst):\n\treturn sum( ([x] if not isinstance(x, list) else flatten(x)\n\tfor x in lst), [] )&colon;

EvalStringflatten([[1],2,[[3],4,5]])

1&comma;2&comma;3&comma;4&comma;5

(4)

Compatibility

• 

The Python[DefineFunction] command was introduced in Maple 2018.

• 

For more information on Maple 2018 changes, see Updates in Maple 2018.

See Also

Python

Python:-EvalString

Python:-EvalFunction