[Tutor] random SUCCESS

Magnus Lyckå magnus@thinkware.se
Wed May 28 17:33:02 2003


At 13:19 2003-05-28 -0500, Jennifer Cianciolo wrote:
>ok, I deleted random.pyc, shut down the program

Yes, if you already *did* "import random" and the wrong
random module got loaded into memory, it won't go away
from memory because you remove the file.

A new "import random" will do nothing if random is loaded
already. This is to avoid the same code existing in multiple
copies in memory. If you build a large program, you might
import the same module in perhaps ten different places.
It will still be loaded just once. This is a Good Thing.
A new "import random" will only make the name "random" in
the part of the program where you made this "import" refer
to the already loaded module.

Even if you do "del random; import random" it will find the
old module which is already loaded in memory.

Still, you don't need to quit Python now. You can type
"reload(random)" after you deleted the bad files, to make
python try to load from a file again. Hopefully, Python
will now find the *right* file. If not, you can see that
at the Python prompt:

 >>> reload(random)
<module 'random' from 'G:\Python22\lib\random.pyc'>

This was the file I wanted!


--
Magnus Lycka (It's really Lyck&aring;), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The shortest path from thought to working program