def importObjectModule(objectName, base=None, finder=imp.find_module, loader=imp.load_module,
    stopAtFailure=False):
    """ Imports a module from a path that may contain object references at the end, and return
        the module and the list of remaining object names."""
    
    module = base
    objectNames = objectName.split(".")
    for i in xrange(0, len(objectNames)):
        name = objectNames[i]
        if module:
            # First try to get the object as an attribute of the module
            child = getattr(module, name, NonExistent)
            if child is NonExistent:
                if isinstance(module, ModuleType):
                    if stopAtFailure:
                        try:
                            module = _importFromModule(name, module, finder, loader)
                        except ImportError,exc:
                            if module is base:
                                try:
                                    module = __import__(name)
                                except ImportError,exc:
                                    return module,objectNames[i:]
                            else:
                                return module,objectNames[i:]
                    else:
                        module = _importFromModule(name, module, finder, loader)
                else:
                    raise ImportError("Unable to import %s" % objectName)
            else:                        
                if not isinstance(child, ModuleType):
                    return module, objectNames[i:]
                else:
                    module = child
                
        else:
            module = _importFromModule(name)
      
    return module,[]
dataset/ETHPy150Open joehewitt/devon/devon/importing.py/importObjectModule/original