Python Glossary Русский

Python 3.4+pathlibterm

pathlib.PurePosixPath

pure paths

A pure path with POSIX semantics (/ separator), regardless of the host OS.

Syntax

pathlib.PurePosixPath(*segments)

Reach for it when you need to parse a POSIX path that came from somewhere else — a config file, a tar archive, a URL — without Windows turning it into backslashes. Comparison is case-sensitive here, so 'A.txt' and 'a.txt' are distinct paths, unlike with PureWindowsPath. It knows nothing about drive letters: for 'C:/x' the drive attribute is empty and 'C:' is just the first component.

Examples

import pathlib
print(pathlib.PurePosixPath('/a/b').parts)   # → ('/', 'a', 'b')
p = pathlib.PurePosixPath('/home/user/report.txt')
print(p.parent, p.name, p.suffix)   # → /home/user report.txt .txt
print(pathlib.PurePosixPath('/a') / 'b' / 'c.txt')   # → /a/b/c.txt
print(pathlib.PurePosixPath('a/b').is_absolute(), pathlib.PurePosixPath('/a/b').is_absolute())   # → False True
print(hasattr(pathlib.PurePosixPath('/a'), 'exists'))   # → False (у чистого пути нет ввода-вывода)

See also

Open in the full glossarydocs.python.orgReport an inaccuracy