python refresh/reload

It’s unclear what you mean with “refresh”, but the normal behavior of Python is that you need to restart the software for it to take a new look on a Python module and reread it.

If your changes isn’t taken care of even after restart, then this is due to one of two errors:

  1. The timestamp on the pyc-file is incorrect and some time in the future.
  2. You are actually editing the wrong file.

You can with reload re-read a file even without restarting the software with the reload() command. Note that any variable pointing to anything in the module will need to get reimported after the reload. Something like this:

import themodule
from themodule import AClass

reload(themodule)
from themodule import AClass

Leave a Comment