Calling custom Python (.py) files will not update with new file saves

3 次查看(过去 30 天)
Hello,
I am currently running R2016a and am interacting with Python 2.7. The script works as intended, and successfully calls the desired .py file (dubbed "master#.py") when needed, using the following commands:
py.importlib.import_module('master14'); ser = py.master14.open_serial_port(); ...
However each time I change and re-save master#.py, Matlab will not recognize any changes I've made and will continue to call on the previous version (that is why I'm currently on #14, because I need to keep changing the file name with each save). This greatly slows down progress because all calls to the .py file then need to be changed in the Matlab code. I have tried deleting the previous .py and .pyc files before re-saving, but that does not work. I suspect that when Matlab first calls on the file, it copies or moves it to another location, so that when I am deleting it from its original spot, the copy remains and is called again with the next run. I don't know where to even begin looking in the file directory to confirm this, however. Additionally, clear commands (i.e., clear all, clear caches, etc.) have not worked, and searching the .py file name in the Matlab dir does not even bring up results.
Has anybody encountered a similar problem??
(BONUS: if you could also advise on how to transfer numeric arrays from Python to Matlab that would be beautiful; I'm currently running a loop that pulls a single value at a time from Python, but the array can be as large as 7000!) Thank you!!

回答(1 个)

Robert Snoeberger
Robert Snoeberger 2017-9-18
编辑:Robert Snoeberger 2017-9-18
You need to reload the module after you change and re-save the .py file. The documentation describes the workflow for making the reloaded module available in MATLAB [1].

类别

Help CenterFile Exchange 中查找有关 Call Python from MATLAB 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by