How to unload a module after I've imported it.
Fuzzyman
fuzzyman at gmail.com
Sun Sep 30 11:17:48 EDT 2007
On Sep 29, 9:32 pm, marvinla <marvinware2... at gmail.com> wrote:
> Have you tried a del?
>
> >> import socket
> >> dir()
>
> ['__builtins__', '__doc__', '__name__', 'socket']>> del socket
> >> dir()
>
> ['__builtins__', '__doc__', '__name__']
>
> See you!
>>> import socket
>>> import sys
>>> 'socket' in sys.modules
True
>>> del sys.modules['socket']
>>> 'socket' in sys.modules
False
Although as Gabriel says, this may not be the best approach for this
particular need.
A new import will do a full reload of the socket module.
Michael
http://www.manning.com/foord
More information about the Python-list
mailing list