On this page
pathlib.PureWindowsPath
Prev: pathlib.PurePosixPath | Up: pathlib | Next: pathlib.UnsupportedOperation
Rel: pathlib.Path, pathlib.PosixPath, pathlib.PurePath, pathlib.PurePosixPath
Ref: docs.python.org — pathlib.PureWindowsPath
Tags: #public #python3 #stdlib #pathlib
Import
import pathlib
from pathlib import PureWindowsPath
Signature & Overview
pathlib.PureWindowsPath(*args, **kwargs)
PurePath subclass for Windows systems.
Methods & Attributes
PureWindowsPath.anchor(...)— The concatenation of the drive and root, or ''.PureWindowsPath.as_posix(self)— Return the string representation of the path with forward (/) slashes.PureWindowsPath.as_uri(self)— Return the path as a URI.PureWindowsPath.drive(...)— The drive prefix (letter or UNC path), if any.PureWindowsPath.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.PureWindowsPath.is_absolute(self)— True if the path is absolute (has both a root and, if applicable, a drive).PureWindowsPath.is_relative_to(self, other)— Return True if the path is relative to another path or False.PureWindowsPath.is_reserved(self)— Return True if the path contains one of the special names reserved by the system, if any.PureWindowsPath.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 isPureWindowsPath.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 thisPureWindowsPath.name(...)— The final path component, if any.PureWindowsPath.parent(...)— The logical parent of the path.PureWindowsPath.parents(...)— A sequence of this path's logical parents.PureWindowsPath.parts(...)— An object providing sequence-like access to the components in the filesystem path.PureWindowsPath.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.PureWindowsPath.root(...)— The root of the path, if any.PureWindowsPath.stem(...)— The final path component, minus its last suffix.PureWindowsPath.suffix(...)— The final component's last suffix, if any.PureWindowsPath.suffixes(...)— A list of the final component's suffixes, if any.PureWindowsPath.with_name(self, name)— Return a new path with the file name changed.PureWindowsPath.with_segments(self, *pathsegments)— Construct a new path object from any number of path-like objects.PureWindowsPath.with_stem(self, stem)— Return a new path with the stem changed.PureWindowsPath.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 PureWindowsPath
# Parse Windows drive letters and UNC paths on any OS
p = PureWindowsPath(r"C:\Users\Ada\report.pdf")
assert p.drive == "C:" and p.root == "\\" and p.name == "report.pdf"
assert p.as_posix() == "C:/Users/Ada/report.pdf"
Gotchas
- Use raw strings (
r"..."): Backslashes in regular string literals can accidentally form escape sequences like\tor\n. - Case-insensitive comparisons:
PureWindowsPath("C:/Foo") == PureWindowsPath("c:/foo")isTrue, unlikePurePosixPath.
REPL Inspect
from pathlib import PureWindowsPath
help(PureWindowsPath)
Linked from
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/PurePath 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/UnsupportedOperation 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/WindowsPath 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