Calling custom Python (.py) files will not update with new file saves
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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!!
0 comentarios
Respuestas (1)
Robert Snoeberger
el 18 de Sept. de 2017
Editada: Robert Snoeberger
el 18 de Sept. de 2017
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].
2 comentarios
Kamran Najeebullah
el 25 de Mayo de 2021
@Robert Snoeberger This link seems to be outdated, cannot find any relavent info there.
Ver también
Categorías
Más información sobre Call Python from MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!