return subclass
+def submods(this_modname, submodnames):
+ """Iterate through (submodname, submod) pairs.
+ """
+ for submodname in submodnames:
+ count = len([s for s in submodnames if s == submodname])
+ assert count > 0, 'No %s entries: %s' % (submodname, submodnames)
+ assert count == 1, 'Multiple (%d) %s entries: %s' \
+ % (count, submodname, submodnames)
+ this_mod = __import__(this_modname, fromlist=[submodname])
+ submod = getattr(this_mod, submodname)
+ yield (submodname, submod)
+
+
def construct_odict(this_modname, submodnames, class_selector,
instantiate=True):
"""Search the submodules `submodnames` of a module `this_modname`
itself is stored.
"""
objs = odict()
- for submodname in submodnames:
- count = len([s for s in submodnames if s == submodname])
- assert count > 0, 'No %s entries: %s' % (submodname, submodnames)
- assert count == 1, 'Multiple (%d) %s entries: %s' \
- % (count, submodname, submodnames)
- this_mod = __import__(this_modname, fromlist=[submodname])
- submod = getattr(this_mod, submodname)
+ for submodname,submod in submods(this_modname, submodnames):
for objname in dir(submod):
obj = getattr(submod, objname)
if class_selector(obj):
is returned.
"""
instances = {}
- for submodname in submodnames:
- count = len([s for s in submodnames if s == submodname])
- assert count > 0, 'No %s entries: %s' % (submodname, submodnames)
- assert count == 1, 'Multiple (%d) %s entries: %s' \
- % (count, submodname, submodnames)
- this_mod = __import__(this_modname, fromlist=[submodname])
- submod = getattr(this_mod, submodname)
+ for submodname,submod in submods(this_modname, submodnames):
for objname in dir(submod):
obj = getattr(submod, objname)
if class_selector(obj):