简体   繁体   English

MATLAB无法从Python脚本导入所有函数

[英]MATLAB not importing all functions from Python script

I'm trying to import functions from a python script. 我正在尝试从python脚本导入函数。 I actually had an old python script, example.py, which looked roughly like this: 我实际上有一个旧的python脚本example.py,看起来大致像这样:

# -*- coding: utf-8 -*-
def A():
  return 1

When I import this module, py.importlib.import_module('example'), it finds function A(). 当我导入py.importlib.import_module('example')这个模块时,它会找到函数A()。

I now add a new function: 我现在添加一个新功能:

# -*- coding: utf-8 -*-
def A():
  return 1
def B():
  return 2

When I now import example, it still only finds A, and not B. 现在,当我导入示例时,它仍然仅找到A,而不找到B。

Is there something I need to do to get MATLAB to detect the new function? 我需要做些什么才能让MATLAB检测新功能吗?

It turns out I needed to reload the module: 事实证明,我需要重新加载模块:

mod = py.importlib.import_module('example');
py.importlib.reload(mod);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM