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

3 ビュー (過去 30 日間)
Damir Janigro
Damir Janigro 2017 年 9 月 14 日
コメント済み: Akshay Jajoo 2021 年 9 月 8 日
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].
  2 件のコメント
Kamran Najeebullah
Kamran Najeebullah 2021 年 5 月 25 日
@Robert Snoeberger This link seems to be outdated, cannot find any relavent info there.
Akshay Jajoo
Akshay Jajoo 2021 年 9 月 8 日
@Robert Snoeberger Content at the link is not much helpful.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCall Python from MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by