Re: How to unload a module after I've imported it.



On Sep 29, 9:32 pm, marvinla <marvinware2...@xxxxxxxxx> 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

.



Relevant Pages