unload/delete modules

Sebastien de Menten sdementen at hotmail.com
Tue Feb 11 09:47:20 EST 2003


Hi,

I have done some research on the topic but it is still very fuzzy...

I have the following script

for i in range(5):
	create_module_foo_with_function_run_that_print_i(i)
	import foo
	foo.run()

The function "create_module_foo_with_function_run_that_print_i(i)" :
 - write a .pyx file (Pyrex file), with code for printing the argument
i
 - translate the file with Pyrex in c code
 - compile the c code to get a foo.so module.

When i run the script, the function always print 0 as if the module
was loaded only once. I think it is the desired behaviour of import.
However, I would like import to reload the file. Hence I tried with a
reload(foo) after import.foo but with no results.
I tried to "del sys.modules['foo']" but the foo.run() function still
exists. Even after deleting it and importing again the module, I get
0.

I have seen a lot of tricks to get a "superreload" function or a
"RollbackImporter" but can't understand the basis of the problem.

Is there any clear/concise explication of the module system in Python
?
Is there a solution for my problem ?

TX for help

Seb




More information about the Python-list mailing list