MATLAB Examples

Call Methods on Python Variables

This example shows how to update a Python® list of folder names using the append method.

Create a list of folders P using the Python sys.path variable.

P = py.sys.path;

Display the Python functions for a list type.

methods(P)
Methods for class py.list:

append   clear    eq       gt       le       mtimes   pop      sort     
cell     copy     extend   index    list     ne       remove   
char     count    ge       insert   lt       plus     reverse  

Call "methods 'handle' " for methods of py.list inherited from handle.

Read the documentation for append.

py.help('list.append')
Help on method_descriptor in list:

list.append = append ... 
    L.append object  -> None -- append object to end

Add the current folder to the end of the path.

append(P,pwd)

Display the number of folders on the path. The list has py.len elements. Your value might be different. The type of this number is py.int.

py.len(P)
ans = 

  Python int with properties:

    denominator: [1×1 py.int]
           imag: [1×1 py.int]
      numerator: [1×1 py.int]
           real: [1×1 py.int]

    8