import utils; reload(utils)
from utils import *
Why does it need load twice? 'reload' is not a built-in function. Right?
import utils; reload(utils)
from utils import *
Why does it need load twice? 'reload' is not a built-in function. Right?
Best way to find out is to check the reload
document, which says:
Python modules’ code is recompiled and the module-level code reexecuted, defining a new set of objects which are bound to names in the module’s dictionary. The init function of extension modules is not called a second time.
As with all other objects in Python the old objects are only reclaimed after their reference counts drop to zero.
The names in the module namespace are updated to point to any new or changed objects.
Other references to the old objects (such as names external to the module) are not rebound to refer to the new objects and must be updated in each namespace where they occur if that is desired.
What does 'reload' do in this case?
That depends on what utils
does... For example, if importing utils
has a side-effect, then that effect will take place again.
Also note that using reload
in any production code is definitely something that you want to avoid. The main reason that reload
exists is for interactive use ...