Python Glossary Русский

Python 3.4+pathlibterm

pathlib.PureWindowsPath

pure paths

A pure path with Windows semantics (\ separator, drive letters), regardless of the host OS.

Syntax

pathlib.PureWindowsPath(*segments)

Comparison and hashing ignore case here, so PureWindowsPath('A/B') equals PureWindowsPath('a/b') — while a PurePosixPath built from the same text never does. Watch the difference between 'C:/data' and 'C:data': the first is anchored at the drive root, the second is relative to the current directory of drive C, and their .parts differ. It runs anywhere, but it cannot open anything — that is what Path is for.

Examples

import pathlib
print(str(pathlib.PureWindowsPath('a', 'b')))   # → a\b
w = pathlib.PureWindowsPath('C:/Users/anna/doc.txt')
print(w.drive, w.name, w.suffix)   # → C: doc.txt .txt
print(w.as_posix())   # → C:/Users/anna/doc.txt
print(pathlib.PureWindowsPath('A/B') == pathlib.PureWindowsPath('a/b'))   # → True (регистр не важен)
print(pathlib.PureWindowsPath('C:/a').is_absolute(), pathlib.PureWindowsPath('/a').is_absolute())   # → True False

See also

Open in the full glossarydocs.python.orgReport an inaccuracy