MATLAB Answers

1

python reload() function matlab 2014b

Asked by Chris Barnhart on 6 Jan 2015
Latest activity Commented on by Robert Snoeberger on 6 Oct 2015
I'm trying to use the python reload() method to reload my an edited python class that I've placed in "myfile.py"
After I first create the object and test it in matlab, changes to the .py file aren't seen. The python IDE has the same issue and one needs to call the built in method reload() - but its unclear what argument to provide it from matlab.
start with creating the object myobj in file myfile.py obj = py.myfile.myobj() then I edit "myfile.py" and need to reload it for the changes to be seen.
py.reload(????)

  0 Comments

Sign in to comment.

4 Answers

Answer by uri merhav on 6 Jan 2015
 Accepted Answer

From the matlab docs under features not supported:
Editing and reloading a Python® module in the same MATLAB session. To use an updated module, restart MATLAB.
A very weird limitation at that, I know. I tried working around it but to no avail...

  1 Comment

The ability to reload edited Python code is available in R2015b. See the item "MATLAB Interface to Python: Clear Python class definitions with clear classes command, useful when reloading revised Python classes" under Advanced Software Development in the R2015b release notes [1].

Sign in to comment.


Answer by Raghav Paul on 4 Sep 2015

This functionality has been incorporated in R2015b using the MATLAB 'clear' command and Python 'import_module' and 'reload' commands. For an example, refer to the link below:

  0 Comments

Sign in to comment.


Answer by Chris Barnhart on 20 Jan 2015

Uri,
I started using system('matlab') to automatically start a new session as a reload() workaround. Seems as though python stdout appears in the first matlab session. Hopefully it'll help you.

  0 Comments

Sign in to comment.


Answer by Chuck37
on 23 Feb 2015

Not being able to reload edited python is a real drag. I hope they fix this soon. Restarting matlab takes too long to fit into a debug loop.

  3 Comments

+1, it's really annoying.
No kidding. I can't believe the isn't fixed yet.

Sign in to comment.