Is there a possible way to immediately reload the Python module?

Is there any conceivable moment for rebooting these modules immediately after importing them? This is the code I was looking at that made me think:

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 creating .pyc files more likely, but several people have indicated that this happens the first time, every time.

+4
source share
4 answers

I note that standard modules have just been imported: these are other modules that are reloaded. I expect that the person who wrote this code would like to easily reload the whole package (to get their latest changes). After entering all these redundant calls reload programmer needed to write

 >>> reload(package) 

to update information in the interpreter, instead of typing

 >>> reload(package.nrrd) >>> reload(package.sm) >>> reload(package.tensPP) 

etc .. Therefore, please ignore the suggestion that you are committing violence against the programmer who wrote this: they are far from the only programmer who had problems reloading dependencies. Just ask them to move the reboot to a convenient function.

+6
source

It is possible that this does lead to something; An obvious example is the side effects that occur during import. For example, a module can write the time and date of each time it is imported into a file.

There is probably no good reason for this.

+6
source

The .pyc files will be created upon first import, so even this is not a good reason for this.

+1
source

What is the runtime environment for this code? There is at least one Python web framework that makes different reboot decisions than standard python, which leads to frustration and confusion when you make changes that don't accept.

0
source

All Articles