relative_path

relative_path(name: str, start: str | None = None) str[source]

Retun a relative path of a given file with respect a given origin.

Parameters:
  • name -- A path to file.

  • start -- An origin of relative path. If the start is not given, the current directory is used as the origin of relative path.

Examples: >>> relative_path('/root/a/b.txt', '/root/c') '../a/b.txt' >>> relative_path('../a/b.txt', './c') '../../a/b.txt'