(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."""
    path = os.fspath(path)
    if isinstance(path, bytes):
        sep = b'\\'
        altsep = b'/'
        curdir = b'.'
        pardir = b'..'
        special_prefixes = (b'\\\\.\\', b'\\\\?\\')
    else:
        sep = '\\'
        altsep = '/'
        curdir = '.'
        pardir = '..'
        special_prefixes = ('\\\\.\\', '\\\\?\\')
    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 apart from the call to os.fspath()
        return path
    path = path.replace(altsep, 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] == curdir:
            del comps[i]
        elif comps[i] == pardir:
            if i > 0 and comps[i-1] != pardir:
                del comps[i-1:i+1]
                i -= 1
            elif i == 0 and prefix.endswith(sep):
                del comps[i]
            else:
                i += 1
        else:
            i += 1
    # If the path is now empty, substitute '.'
    if not prefix and not comps:
        comps.append(curdir)
    return prefix + sep.join(comps)
def normpath ( path ) : path = os . fspath ( path ) if isinstance ( path , bytes ) : sep = b'\\' altsep = b'/' curdir = b'.' pardir = b'..' special_prefixes = ( b'\\\\.\\' , b'\\\\?\\' ) else : sep = '\\' altsep = '/' curdir = '.' pardir = '..' special_prefixes = ( '\\\\.\\' , '\\\\?\\' ) 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 apart from the call to os.fspath() return path path = path . replace ( altsep , 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 ] == curdir : del comps [ i ] elif comps [ i ] == pardir : if i > 0 and comps [ i - 1 ] != pardir : del comps [ i - 1 : i + 1 ] i -= 1 elif i == 0 and prefix . endswith ( sep ) : del comps [ i ] else : i += 1 else : i += 1 # If the path is now empty, substitute '.' if not prefix and not comps : comps . append ( curdir ) return prefix + sep . join ( comps )