Main Content

pyargs

Create keyword arguments for Python function

Description

example

kwa = pyargs(argKey,argValue) creates one or more keyword arguments to pass to a Python® function. A Python keyword argument is a value preceded by an identifier. Place pyargs as the final input argument to a Python function. For example:

py.print('a','b',pyargs('sep',','))

Examples

collapse all

The Python complex function has keyword arguments real and imag. When you call this function in MATLAB®, use either the pyargs function or name=value syntax. Do not mix the two calling formats.

Call the function with a pyargs argument.

py.complex(pyargs('real',1,'imag',2))
ans = 

  Python complex with properties:

    imag: 2
    real: 1

    (1+2j)

Alternatively, call the function with name=value syntax.

py.complex(real=1,imag=2);

Input Arguments

collapse all

Python function keyword arguments specified as one or more comma-separated pairs of argKey,argValue arguments. argKey is the Python function key name and is a string or character vector. argValue is the argument value, represented by any valid Python type. Use the Python function argument list to identify argKey and argValue. You can specify several key and value pair arguments in any order as argKey1,argValue1,...,argKeyN,argValueN.

Example: 'length',int32(2)

Limitations

  • Do not combine pyargs and name=value syntax when passing keyword arguments to Python functions.

  • MATLAB does not support name,value syntax for passing keyword arguments to Python functions. Use name=value syntax instead.

Alternative Functionality

You can pass Python keyword arguments using MATLAB name=value syntax. For more information, see Call Python complex Function Using Keyword Arguments.

Version History

Introduced in R2014b

expand all

Behavior changed in R2021b