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 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