Is there any possible point to reloading a Python module immediately?
Is there any conceivable point to reloading these modules immediately after importing them? This is the code that I was reviewing which made me wonder:
import time import sys import os import string import pp import numpy import nrrd reload(nrrd) import smooth as sm reload(sm) import TensorEval2C as tensPP reload(tensPP) import TrackFiber4C as trackPP reload(trackPP) import cmpV reload(cmpV) import vectors as vects reload(vects)
Edit: I suggested that this might make the creation of .pyc files more likely, but several people pointed out that this happens this first time, every time.
I note that the standard modules are just imported: it's the other modules that are reloaded. I expect whoever wrote this code wanted to be able to easily reload the whole package (so as to get their latest edits). After putting in all these redundant reload calls, the programmer only had to write
to bring things up to date in the interpreter, instead of having to type
>>> reload(package.nrrd) >>> reload(package.sm) >>> reload(package.tensPP)
etc. So please ignore the suggestion that you commit violence against the programmer who wrote this: they are far from the only programmer who's had trouble with reloading of dependencies. Just encourage them to move the reloads to a convenience function.
It is possible that this does cause something to happen; the obvious example is side-effects that happen on import. For instance, a module could log to a file the time and date of every time it is imported.
There is probably no good reason for this, however.