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

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


It runs, but what does it do?

If test.py contains the single line
print 'this is a test'

then from the interpreter we have this:
 >>> import test
this is a test
 >>> del test
 >>> import test

Note it doesn't print anything here

 >>> reload(test)
this is a test
<module 'test' from 'test.pyc'>

Now it prints again.

Kent

At 07:14 PM 10/21/2004 -0500, Jacob S. wrote:
> >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.
>
>I ran it on the interpreter, and it tested out okay. I don't know if that
>matters any, but it stands with me.
>Jacob
>
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor



More information about the Tutor mailing list