(path)
return prefix + sep.join(comps)
Normalize path, eliminating double slashes, etc.
Normalize path, eliminating double slashes, etc.
Normalize path eliminating double slashes etc .
def normpath(path):
    """Normalize path, eliminating double slashes, etc."""
    sep = _get_sep(path)
    dotdot = _get_dot(path) * 2
    special_prefixes = _get_special(path)
    if path.startswith(special_prefixes):
        # in the case of paths with these prefixes:
        # \\.\ -> device names
        # \\?\ -> literal paths
        # do not do any normalization, but return the path unchanged
        return path
    path = path.replace(_get_altsep(path), sep)
    prefix, path = splitdrive(path)

    # collapse initial backslashes
    if path.startswith(sep):
        prefix += sep
        path = path.lstrip(sep)

    comps = path.split(sep)
    i = 0
    while i < len(comps):
        if not comps[i] or comps[i] == _get_dot(path):
            del comps[i]
        elif comps[i] == dotdot:
            if i > 0 and comps[i-1] != dotdot:
                del comps[i-1:i+1]
                i -= 1
            elif i == 0 and prefix.endswith(_get_sep(path)):
                del comps[i]
            else:
                i += 1
        else:
            i += 1
    # If the path is now empty, substitute '.'
    if not prefix and not comps:
        comps.append(_get_dot(path))
    return prefix + sep.join(comps)
def normpath ( path ) : sep = _get_sep ( path ) dotdot = _get_dot ( path ) * 2 special_prefixes = _get_special ( path ) if path . startswith ( special_prefixes ) : # in the case of paths with these prefixes: # \\.\ -> device names # \\?\ -> literal paths # do not do any normalization, but return the path unchanged return path path = path . replace ( _get_altsep ( path ) , sep ) prefix , path = splitdrive ( path ) # collapse initial backslashes if path . startswith ( sep ) : prefix += sep path = path . lstrip ( sep ) comps = path . split ( sep ) i = 0 while i < len ( comps ) : if not comps [ i ] or comps [ i ] == _get_dot ( path ) : del comps [ i ] elif comps [ i ] == dotdot : if i > 0 and comps [ i - 1 ] != dotdot : del comps [ i - 1 : i + 1 ] i -= 1 elif i == 0 and prefix . endswith ( _get_sep ( path ) ) : del comps [ i ] else : i += 1 else : i += 1 # If the path is now empty, substitute '.' if not prefix and not comps : comps . append ( _get_dot ( path ) ) return prefix + sep . join ( comps )