sorry, im sure this is asked a bunch, but i couldnt find it.
in myModule.py:
from myModule.subModule import myClass
i am working on myClass, and want to stay in my ipython session and test it. reload(myModule) doesnt re-compile myClass.
how can i do this?
You need to repeat your imports after reloading the “leafmost” submodule. E.g., given:
and then
and in another terminal
then…:
You need to go via
sys.modulesas you don’t otherwise have a reference to the submodule, and then you need to repeat thefrom.Life is much simpler if you accept the wise advice of always importing a module, never stuff from INSIDE the module, of course – e.g., the Python session would be (with a change to the submodule before the reload):
If you get into the habit of using qualified names such as
sm.MyClassinstead of only the barenameMyClass, your life will be simpler in many respects (easier reloading is just one of them;-).