Python Glossary Русский

Python 3.4+until 3.15pathlibfunction

pathlib.PurePath.is_reserved()

removed

Checked whether a path name is reserved on Windows (NUL, CON). Removed in Python 3.15 — use os.path.isreserved().

Syntax

PureWindowsPath('nul').is_reserved()  # до 3.15

The method returned True for names such as NUL, CON or COM1 that Windows refuses as file names, and was always False for POSIX paths. It was removed because the Windows rules are subtler than the method handled, and the check moved to os.path. To migrate, replace path.is_reserved() with os.path.isreserved(path), which exists on Windows only, since 3.13. To check a name against Windows rules on any system, call ntpath.isreserved(path): ntpath is the Windows implementation of os.path and imports everywhere.

Examples

# Python 3.15+
import pathlib
try:
    pathlib.PurePath.is_reserved
except AttributeError as e:
    print(type(e).__name__)  # → AttributeError
# Python 3.15+
import ntpath
print(ntpath.isreserved('NUL'), ntpath.isreserved('notes.txt'))  # → True False
from pathlib import PurePosixPath, PureWindowsPath
print(PureWindowsPath('nul').is_reserved())  # → True
print(PurePosixPath('nul').is_reserved())  # → False

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy