(path, forceload=0)
return object
Locate an object by name or dotted path, importing as necessary.
Locate an object by name or dotted path, importing as necessary.
Locate an object by name or dotted path importing as necessary .
def locate(path, forceload=0):
    """Locate an object by name or dotted path, importing as necessary."""
    parts = [part for part in path.split('.') if part]
    module, n = None, 0
    while n < len(parts):
        nextmodule = safeimport('.'.join(parts[:n+1]), forceload)
        if nextmodule: module, n = nextmodule, n + 1
        else: break
    if module:
        object = module
    else:
        object = builtins
    for part in parts[n:]:
        try:
            object = getattr(object, part)
        except AttributeError:
            return None
    return object
def locate ( path , forceload = 0 ) : parts = [ part for part in path . split ( '.' ) if part ] module , n = None , 0 while n < len ( parts ) : nextmodule = safeimport ( '.' . join ( parts [ : n + 1 ] ) , forceload ) if nextmodule : module , n = nextmodule , n + 1 else : break if module : object = module else : object = builtins for part in parts [ n : ] : try : object = getattr ( object , part ) except AttributeError : return None return object