Main Content

pyargs

Create keyword arguments forPythonfunction

Description

example

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

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

Examples

collapse all

The Pythoncomplexfunction has keyword argumentsrealandimag。When you call this function in MATLAB®,使用pyargsfunction orname=valuesyntax. Do not mix the two calling formats.

Call the function with apyargsargument.

py.complex(pyargs('real',1,'imag',2))
ans = Python complex with properties: imag: 2 real: 1 (1+2j)

Alternatively, call the function withname=valuesyntax.

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

Input Arguments

collapse all

Python function keyword arguments specified as one or more comma-separated pairs ofargKey,argValuearguments.argKeyis the Python function key name and is a string or character vector.argValueis the argument value, represented by any valid Python type. Use the Python function argument list to identifyargKeyandargValue。您可以指定几个关键and value pair arguments in any order asargkey1,argvalue1,...,argkeyn,argvaluen

Example:'length',int32(2)

Limitations

  • Do not combinepyargsandname=valuesyntax when passing keyword arguments to Python functions.

  • MATLAB does not support名称,价值syntax for passing keyword arguments to Python functions. Usename=valuesyntax instead.

Alternative Functionality

You can pass Python keyword arguments using MATLABname=valuesyntax. For more information, seeCall Python complex Function Using Keyword Arguments

Version History

在R2014b中引入

expand all

Behavior changed in R2021b