Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 410
Thomas Avatar asked Dec 12 '22 18:12

Thomas


1 Answers

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

>>> reload(package)

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.

like image 109
Gareth Rees Avatar answered Jan 22 '23 18:01

Gareth Rees