Python Glossary Русский

all Python 3osfunction

os.path.normcase

os.path — path parsing

Normalizes path case and separators: unchanged on POSIX, lower-cased with / turned into \ on Windows.

Syntax

os.path.normcase(path)

It is for comparing paths, not displaying them: on Windows the result is lower-cased with backslashes, so do not show it to users. It neither resolves links nor removes '..' — combine it with normpath for a full comparison, or use samefile. On macOS the filesystem is usually case-insensitive too, yet normcase changes nothing there.

Examples

import os
print(os.path.normcase('abc'))   # → abc
print(os.path.normcase('Dir/File.TXT'))   # → на POSIX без изменений: Dir/File.TXT; на Windows: dir\file.txt
print(os.path.normcase('C:/Temp/A.TXT') == os.path.normcase('c:\\temp\\a.txt'))   # → на Windows True, на POSIX False
print(os.path.normcase('a/../b') != os.path.normpath('a/../b'))   # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy