PurePath.parent
The logical parent of the path:
1 2 3 | >>> p = PurePosixPath( '/a/b/c/d' ) >>> p.parent PurePosixPath( '/a/b/c' ) |
You cannot go past an anchor, or empty path:
1 2 3 4 5 6 | >>> p = PurePosixPath( '/' ) >>> p.parent PurePosixPath( '/' ) >>> p = PurePosixPath( '.' ) >>> p.parent PurePosixPath( '.' ) |
Note
This is a purely lexical operation, hence the following behaviour:
1 2 3 | >>> p = PurePosixPath( 'foo/..' ) >>> p.parent PurePosixPath( 'foo' ) |
If you want to walk an arbitrary filesystem path upwards, it is recommended to first call Path.resolve()
so as to resolve symlinks and eliminate ”..” components.
Please login to continue.