On this page
pathlib.PurePath
Prev: pathlib.PosixPath | Up: pathlib | Next: pathlib.PurePosixPath
Rel: pathlib.Path, pathlib.PosixPath, pathlib.PurePosixPath, pathlib.PureWindowsPath
Ref: docs.python.org — pathlib.PurePath
Tags: #public #python3 #stdlib #pathlib
Import
import pathlib
from pathlib import PurePath
Signature & Overview
pathlib.PurePath(*args, **kwargs)
Base class for manipulating paths without I/O.
Methods & Attributes
PurePath.anchor(...)— The concatenation of the drive and root, or ''.PurePath.as_posix(self)— Return the string representation of the path with forward (/) slashes.PurePath.as_uri(self)— Return the path as a URI.PurePath.drive(...)— The drive prefix (letter or UNC path), if any.PurePath.full_match(self, pattern, *, case_sensitive=None)— Return True if this path matches the given glob-style pattern. The pattern is matched against the entire path.PurePath.is_absolute(self)— True if the path is absolute (has both a root and, if applicable, a drive).PurePath.is_relative_to(self, other)— Return True if the path is relative to another path or False.PurePath.is_reserved(self)— Return True if the path contains one of the special names reserved by the system, if any.PurePath.joinpath(self, *pathsegments)— Combine this path with one or several arguments, and return a new path representing either a subpath (if all arguments are relative paths) or a totally different path (if one of the arguments isPurePath.match(self, path_pattern, *, case_sensitive=None)— Return True if this path matches the given pattern. If the pattern is relative, matching is done from the right; otherwise, the entire path is matched. The recursive wildcard '**' is not supported by thisPurePath.name(...)— The final path component, if any.PurePath.parent(...)— The logical parent of the path.PurePath.parents(...)— A sequence of this path's logical parents.PurePath.parts(...)— An object providing sequence-like access to the components in the filesystem path.PurePath.relative_to(self, other, *, walk_up=False)— Return the relative path to another path identified by the passed arguments. If the operation is not possible (because this is not related to the other path), raise ValueError.PurePath.root(...)— The root of the path, if any.PurePath.stem(...)— The final path component, minus its last suffix.PurePath.suffix(...)— The final component's last suffix, if any.PurePath.suffixes(...)— A list of the final component's suffixes, if any.PurePath.with_name(self, name)— Return a new path with the file name changed.PurePath.with_segments(self, *pathsegments)— Construct a new path object from any number of path-like objects.PurePath.with_stem(self, stem)— Return a new path with the stem changed.PurePath.with_suffix(self, suffix)— Return a new path with the file suffix changed. If the path has no suffix, add given suffix. If the given suffix is an empty string, remove the suffix from the path.
Usage
from pathlib import PurePath
p = PurePath("src", "app", "main.py")
assert p.name == "main.py"
assert p.with_suffix(".pyc").name == "main.pyc"
assert p.with_stem("cli").name == "cli.py"
Gotchas
- No filesystem I/O:
PurePathonly manipulates path strings—it does not provide.exists(),.open(),.mkdir(), or.resolve(). - Host-OS flavored:
PurePath()creates aPurePosixPathon Unix andPureWindowsPathon Windows; pickPurePosixPathorPureWindowsPathexplicitly for cross-OS parsing.
REPL Inspect
from pathlib import PurePath
help(PurePath)
Linked from
- tuts/python3/stdlib_module/pathlib
- tuts/python3/stdlib_module/pathlib/Path
- tuts/python3/stdlib_module/pathlib/PosixPath
- tuts/python3/stdlib_module/pathlib/PurePosixPath
- tuts/python3/stdlib_module/pathlib/PureWindowsPath
- tuts/python3/stdlib_module/pathlib/UnsupportedOperation
- tuts/python3/stdlib_module/pathlib/WindowsPath
Related notes
- tuts/python3/stdlib_module/pathlib/Path Linked here; links to this page; shared tags: #pathlib, #stdlib
- tuts/python3/stdlib_module/pathlib/PosixPath Linked here; links to this page; shared tags: #pathlib, #stdlib
- tuts/python3/stdlib_module/pathlib/PurePosixPath Linked here; links to this page; shared tags: #pathlib, #stdlib
- tuts/python3/stdlib_module/pathlib/PureWindowsPath Linked here; links to this page; shared tags: #pathlib, #stdlib
- tuts/python3/stdlib_module/pathlib Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/pathlib/UnsupportedOperation links to this page; shared tags: #pathlib, #stdlib
- tuts/python3/stdlib_module/pathlib/WindowsPath links to this page; shared tags: #pathlib, #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib