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. Thepyargsfunction is the only way to create keyword arguments in MATLAB®。Use this function when creatingpy.dictvariables.

Examples

collapse all

The Pythoncalendar.TextCalendar.formatmonthmethod displays a monthly calendar. The method takes two keyword arguments. The keywordwspecifies the width of the date columns. The keywordl指定每周的行数。

Create a calendar.

cal = py.calendar.TextCalendar;

Display the calendar for December 2014 using the default line spacing and column width.

FormatMonth(Cal,Int32(2014),INT32(12))
ans = Python str with no properties. December 2014 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

Display the function signature from the Python documentation for thecalendar.TextCalendar.formatmonthfunction.

py.help('calendar.TextCalendar.formatmonth')
Help on method formatmonth in calendar.TextCalendar: calendar.TextCalendar.formatmonth = formatmonth(self, theyear, themonth, w=0, l=0) unbound calendar.TextCalendar method Return a month's calendar string (multi-line).

Notice that argumentswandlare optional, with default values of0

Now display the function signatures in MATLAB.

methods(cal,'-满的')

Search the output for theformatmonthfunction signature.

lhs formatmonth(self, theyear, themonth, w, l, pyargs)

Change the value of the line spacing argument to2以及宽度论点的价值3using apyargsargument.

formatmonth(cal,int32(2014),int32(12),pyargs('l',int32(2),'w',int32(3)))
ans = Python str with no properties. December 2014 Mon Tue Wed Thu Fri Sat Sun 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31

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 function argument list to identifyargKeyandargValue。你可以年代pecify several key and value pair arguments in any order asargkey1,argvalue1,...,argkeyn,argvaluen

Example:'length',int32(2)

Limitations

  • name=valuesyntax not supported for calls to Python functions usingpy.prefix

在R2014b中引入