Python Glossary Русский

Python 3.4+pathlibterm

pathlib.PosixPath

concrete paths

A concrete path with I/O on POSIX systems (Linux/macOS); what Path() returns there.

Syntax

pathlib.PosixPath(*segments)

You almost never need to name PosixPath yourself: Path() picks the right class per OS, and on Windows constructing PosixPath fails outright with UnsupportedOperation (NotImplementedError before 3.13). To parse a POSIX-style path on any platform without touching the disk, use PurePosixPath instead. A common debugging surprise: printing a list of paths shows their repr, PosixPath('a/b'), while the bare path string comes from str(p).

Examples

import pathlib
print(issubclass(pathlib.PosixPath, pathlib.PurePosixPath))   # → True
print(issubclass(pathlib.PosixPath, pathlib.Path))   # → True
print(issubclass(pathlib.PosixPath, pathlib.WindowsPath))   # → False
print(hasattr(pathlib.PosixPath, 'read_text'), hasattr(pathlib.PurePosixPath, 'read_text'))   # → True False
print(type(pathlib.Path()).__name__)   # → PosixPath на Linux/macOS, WindowsPath на Windows

See also

Open in the full glossarydocs.python.orgReport an inaccuracy