(path, start=curdir)
return join(*rel_list)
Return a relative version of a path
Return a relative version of a path
Return a relative version of a path
def relpath(path, start=curdir):
    """Return a relative version of a path"""
    sep = _get_sep(path)

    if start is curdir:
        start = _get_dot(path)

    if not path:
        raise ValueError("no path specified")

    start_abs = abspath(normpath(start))
    path_abs = abspath(normpath(path))
    start_drive, start_rest = splitdrive(start_abs)
    path_drive, path_rest = splitdrive(path_abs)
    if normcase(start_drive) != normcase(path_drive):
        error = "path is on mount '{0}', start on mount '{1}'".format(
            path_drive, start_drive)
        raise ValueError(error)

    start_list = [x for x in start_rest.split(sep) if x]
    path_list = [x for x in path_rest.split(sep) if x]
    # Work out how much of the filepath is shared by start and path.
    i = 0
    for e1, e2 in zip(start_list, path_list):
        if normcase(e1) != normcase(e2):
            break
        i += 1

    if isinstance(path, bytes):
        pardir = b'..'
    else:
        pardir = '..'
    rel_list = [pardir] * (len(start_list)-i) + path_list[i:]
    if not rel_list:
        return _get_dot(path)
    return join(*rel_list)
def relpath ( path , start = curdir ) : sep = _get_sep ( path ) if start is curdir : start = _get_dot ( path ) if not path : raise ValueError ( "no path specified" ) start_abs = abspath ( normpath ( start ) ) path_abs = abspath ( normpath ( path ) ) start_drive , start_rest = splitdrive ( start_abs ) path_drive , path_rest = splitdrive ( path_abs ) if normcase ( start_drive ) != normcase ( path_drive ) : error = "path is on mount '{0}', start on mount '{1}'" . format ( path_drive , start_drive ) raise ValueError ( error ) start_list = [ x for x in start_rest . split ( sep ) if x ] path_list = [ x for x in path_rest . split ( sep ) if x ] # Work out how much of the filepath is shared by start and path. i = 0 for e1 , e2 in zip ( start_list , path_list ) : if normcase ( e1 ) != normcase ( e2 ) : break i += 1 if isinstance ( path , bytes ) : pardir = b'..' else : pardir = '..' rel_list = [ pardir ] * ( len ( start_list ) - i ) + path_list [ i : ] if not rel_list : return _get_dot ( path ) return join ( * rel_list )