ID EN
Pathlib

is_relative_to

Python 3.11

Return whether or not this path is relative to the other path.

Syntax

PYTHON
PurePath.is_relative_to(*other)

Examples

Example 1
PYTHON
>>> p = PurePath('/etc/passwd')
>>> p.is_relative_to('/etc')
True
>>> p.is_relative_to('/usr')
False
Example 2
PYTHON
>>> u = PurePath('/usr')
>>> u == p or u in p.parents
False