[Tutor] A way to restart a script after it runs?

Kent Johnson kent_johnson at skillsoft.com
Fri Oct 22 02:02:59 CEST 2004

I'm not sure what the OP wants to accomplish, but this probably won't do 
it. Imported modules are cached in sys.modules. 'del myscript' unbinds the 
name myscript from <module 'myscript'> in the current namespace; it doesn't 
actually unload the module itself.

reload(myscript) may do what you want, it will force the module to be 
reloaded. A better description of the problem would help.


At 06:07 PM 10/21/2004 -0500, Jacob S. wrote:
>You might try something like:
>     >>> import myscript  ## Myscript will have an if __name__ = "myscript"
>check because you are importing it...
>     >>> print myscript
>     <module 'myscript' from [:Drive][:Path][myscript.pyc]>
>      >>> ## This means it's an object. So we should be able to free the
>memory and delete it
>     >>> del myscript
>     >>>import myscript
>Jacob Schmidt
>Tutor maillist  -  Tutor at python.org

More information about the Tutor mailing list