modules = []
for f in os.listdir("modules"):
if f.startswith("mod_"):
if f.endswith(".pyc"):
minus = 4
else:
minus = 3
module = "modules."+f[:-minus]
if module in doneModules:
continue
doneModules.append(module)
print "Importing %s"%(module)
modules.append(__import__(module,globals(),locals(),["modules"]))
The only really interesting part is the last line in the loop. Here a new module is loaded an appended to the modules list. Since the modules are in the "modules" package the last parameter of the import call is no longer optional. Otherwise you'd only do a import modules.mod_whatever instead of a from modules import mod_whatever.
Another note: The first parameter has to be in this case "modules.mod_whatever" and not only "mod_whatever". If you forget this you will get a "module not found" error.
Comments: