"Chmouel Boudjnah" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > dir = listdir('/path/') > for i in dir: > sys.path.append('/path/' + i "/") > import Module > doStuff() > sys.path.remove('/path/' + i "/") > > it's obviously not working since it get only the first import Module > while the others doent get replaced, the only solution for me was too : > > sys.modules.pop('Module')
Yes, Python's import mechanism assumes that sys.path is relatively static, or grow only. I not sure what 'reload Module' would do after the first loop. > which after it does works fine. But my question is what's happenning in > the internals, does it free the memory of Module to do a sys.modules.pop > ? A Python implementation *may* 'free' an object anytime after the last reference to the object disappears. Whether the name Module and the slot in sys.modules are the only two references depends, I believe, on both the code in the module and the code the uses it. sys.getrefcount() can help answer this. Terry J. Reedy -- http://mail.python.org/mailman/listinfo/python-list