reload/import module bug?

Cezar Ionescu ionescu at pik-potsdam.de
Tue Sep 14 04:13:31 EDT 1999


"David J. Fish":
> 
>    I have recently discovered a feature in Python which does not seem to
> make
> a whole lot of sense.
[snip]
> Then, back at the interactive prompt:
> >>> del(knights)
> >>> import knights
> >>> reload(knights)

My understanding is that the import statement, when first run, causes:
	a) load of the module, compilation of the module
	b) assigning the code to the name of the module
del then only unbinds the top level name from the code. 
If after del you do
import sys
print sys.modules

you'll see your module still in the internal modules table.

So you have to do 

del(sys.modules['knights'])

if what you want is to get rid of the module *code* And then you just
need to import the module, and not reload it after that.

(Come to think of it, why did you reload the module after the second
import? Presumably, you had thought that del removed the module code, or
I have just misinterpreted your question...)

Otherwise, reload just gets the updated exports, i.e. in this case adds
echoer.

Hope this makes sense,
Cezar.




More information about the Python-list mailing list