I also have noticed another (to me) strange thing about module imports. If anyone could explain this to me, that would be great (I apologize if it's too elementary for this list.) <br><br>Suppose I have a module <br><br>
#file: testmodule.py<br> a = 1<br><br><br>When importing this module, obviously 'a' becomes an attribute of testmodule:<br><br> >>> import testmodule<br> >>> dir(testmodule)<br> ['__builtins__', '__doc__', '__file__', '__name__', 'a']<br>
<br><br>Now, supposed I modify the file to:<br><br> #file: testmodule.py<br>
A = 1<br>
<br>and then reload:<br><br> >>> reload(testmodule)<br> <module 'testmodule' from 'testmodule.py'><br><br>Now, the reported attributes still include the old 'a':<br><br> >>> dir(testmodule)<br>
['A', '__builtins__', '__doc__', '__file__', '__name__', 'a']<br><br>Why does this happen?<br><br>Moreover, even if I delete the module from memory and then reload, I _still_ get the old attribute 'a':<br>
<br> >>> del testmodule<br> >>> import testmodule<br> >>> dir(testmodule)<br> ['A', '__builtins__', '__doc__', '__file__', '__name__', 'a']<br>
<br>What is the principle behind this? And, is there some simple way (other than restarting the interpreter) of "reloading" that wipes out the old attributes associated with a given name so that spurious attributes do not remain?<br>
<br>Thanks again (and apologies of this is a stupid question)<br><br>Dan<br><br>