Python Node

Calls a Python function directly.

The Python Node is expandable and shows data types for the wired inputs and outputs. You can configure the Python Node to specify the Python session, module path, and function name.

The Python Node is not supported on real-time or FPGA targets.


icon

Inputs/Outputs

  • cgnrn.png session in

    session in specifies a reference to the Python session. One or more Python Nodes can run in a single Python session.

  • cpath.png module path

    module path specifies the path to the Python module. The module contains the Python function to call.

  • cstr.png function name

    function name specifies the name of the Python function to call.

  • cerrcodeclst.png error in (no error)

    error in describes error conditions that occur before this node runs. This input provides standard error in functionality.

  • cpoly.png return type

    return type specifies the data type of return value.

    You must wire the data type to return type to indicate the expected data type of return value. If the Python function does not return any value, leave return type unwired.
  • cpoly.png input parameter

    input parameter specifies the input parameters of the Python function.

    You can resize the Python Node to add more terminals. You pass a value to the Python function by wiring to the left terminal of a terminal pair. You read the value of a parameter after the function call by wiring from the right terminal of a terminal pair.
  • ignrn.png session out

    session out returns a reference to the Python session.

  • ierrcodeclst.png error out

    error out contains error information. This output provides standard error out functionality.

  • ipoly.png return value

    return value is the return value of the Python function.

  • ipoly.png

  • Supported Data Types

    The Python Node supports a large number of data types. You can use this node to call the following data types:

    • Numerics
    • Arrays, including multi-dimensional arrays
    • Strings
    • Clusters
    • Booleans

    Calling Conventions

    This node converts integers, strings, and Booleans to the corresponding data types in Python, converts arrays to lists or NumPy arrays, and converts clusters to tuples.

    Marshaling Arrays to Lists or NumPy Arrays

    By default, the Python Node marshals arrays to lists. To marshal an array wired to input parameter to a NumPy array, right-click input parameter and select Marshal to NumPy Array from the shortcut menu.

    Note You can marshal only numeric arrays to NumPy arrays.

    Marshaling Clusters to Named Tuples

    By default, the Python Node marshals clusters to tuples. In Python, you can only reference items in a tuple by index and iterator. Python supports named tuples, which allow you to reference items by name as well. If you want to reference named tuple items by name, you must marshal clusters to named tuples. To marshal a cluster wired to an input parameter to a named tuple, right-click input parameter and select Marshal to Namedtuple from the shortcut menu.