Steven D'Aprano
2015-08-11 11:38:00 UTC
HI there!!
I try to develop some scripts. I use ipython for check if my script work.
When I change the script and try to import again that script I'm not
able to see the modification so I need every time close ipython and
run again and import the script. How can do the refresh of library
without close ipython? thanks so much!
In Python 2:I try to develop some scripts. I use ipython for check if my script work.
When I change the script and try to import again that script I'm not
able to see the modification so I need every time close ipython and
run again and import the script. How can do the refresh of library
without close ipython? thanks so much!
import mymodule
# make some changes
reload(mymodule)
But be careful that objects attached to the module are *not* updated to
use the new module!
import mymodule
x = mymodule.MyClass()
reload(mymodule)
x.method()
x still uses the old version of the class and method, and will *not* use
the new one. You have to throw it away and start again:
reload(mymodule)
x = mymodule.MyClass()
x.method()
Now you will see the new behaviour.
In Python 3, everything is the same except you have to do:
from imp import reload
first.
--
Steve
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor
Steve
_______________________________________________
Tutor maillist - ***@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor