[Tutor] Which modules have been imported?

Remco Gerlich scarblac@pino.selwerd.nl
Sun, 18 Mar 2001 21:07:49 +0100


On Sun, Mar 18, 2001 at 02:44:41PM -0000, bwgolling wrote:
> I am trying to learn Python but am having a problem keeping up with which
> modules I have loaded.  I discovered somewhat by accident that I can unload
> a module with 'del', but is there a command that will print a list of
> exactly what modules are still loaded?

A module isn't actually unloaded when you del it, it's simply not accessible
under that name anymore in the current namespace.

If you want to know all the names in the current namespace, use dir().

All the modules currently loaded in the system are in sys.modules. So import
sys and print sys.modules.

(For a nicer way to view it, use prettyprint:
import sys, pprint
pprint.pprint(sys.modules)
)

But usually there's no need to unload modules.

-- 
Remco Gerlich