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

3 vues (au cours des 30 derniers jours)
Damir Janigro
Damir Janigro le 14 Sep 2017
Commenté : Akshay Jajoo le 8 Sep 2021
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!!

Réponses (1)

Robert Snoeberger
Robert Snoeberger le 18 Sep 2017
Modifié(e) : Robert Snoeberger le 18 Sep 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 commentaires
Kamran Najeebullah
Kamran Najeebullah le 25 Mai 2021
@Robert Snoeberger This link seems to be outdated, cannot find any relavent info there.
Akshay Jajoo
Akshay Jajoo le 8 Sep 2021
@Robert Snoeberger Content at the link is not much helpful.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Call Python from MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by