将当前文件夹更改为可写文件夹。
在 MATLAB 编辑器中打开一个新文件。
复制下列命令并将该文件另存为 mymod.py。
# mymod.py
"""Python module demonstrates passing MATLAB types to Python functions"""
def search(words):
"""Return list of words containing 'son'"""
newlist = [w for w in words if 'son' in w]
return newlist
def theend(words):
"""Append 'The End' to list of words"""
words.append('The End')
return words
从 MATLAB 命令提示符下,将当前文件夹添加到 Python 搜索路径。
if count(py.sys.path,'') == 0
insert(py.sys.path,int32(0),'');
end
要了解如何调用函数,请阅读 mymod.py 源文件中 search 函数的函数签名。该函数接受一个输入参数 words。
def search(words):
阅读 mymod.py 源文件中的函数帮助。根据 Python 网站文档,帮助位于“作为模块、函数、类或方法定义中的第一条语句出现的字符串文字”中。search 的帮助是