recursive import list

wittempj@hotmail.com martin.witte at gmail.com
Mon Jun 13 22:17:33 CEST 2005


If you use your own import function, like below, you could create a
list of all imported modules.

#!/usr/bin/env python

mod_list = []

def my_import(name, globals = None, locals = None, fromlist = None):
    mod_list.append(name)
    mod = __import__(name, globals, locals, fromlist)
    return mod

os = my_import('os')
print os.name

print mod_list

sys = my_import('sys')
print sys.version

print mod_list




More information about the Python-list mailing list