Create keyword arguments for Python function



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. The pyargs function is the only way to create keyword arguments in MATLAB®. Use this function when creating py.dict variables.


collapse all

The Python calendar.TextCalendar.formatmonth method displays a monthly calendar. The method takes two keyword arguments. The keyword w specifies the width of the date columns. The keyword l specifies the number of lines for each week.

Create a calendar.

cal = py.calendar.TextCalendar;

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

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 the calendar.TextCalendar.formatmonth function.'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 arguments w and l are optional, with default values of 0.

Now display the function signatures in MATLAB.


Search the output for the formatmonth function signature.

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

Change the value of the line spacing argument to 2 and the value of the width argument to 3 using a pyargs argument.

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 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 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)

Introduced in R2014b