all Python 3osfunction
os.path.lexists
os.path — existence and type checks
Like exists, but does not follow symlinks (True even for a broken link).
Syntax
os.path.lexists(path)
Use it when the link itself matters, not its target: before creating a symlink or while cleaning up broken ones. Together exists and lexists detect a broken link: lexists(p) and not exists(p). On systems without symlinks it behaves like exists.
Examples
import os
print(os.path.lexists(os.__file__)) # → True
print(os.path.lexists('нет-такого-файла.txt')) # → False
print(os.path.lexists(os.path.dirname(os.__file__))) # → True
print(os.path.exists(os.__file__), os.path.lexists(os.__file__)) # → True True
import os
# на Unix: os.symlink('нет-такой-цели', 'битая') — после этого os.path.exists('битая') даст False, а os.path.lexists('битая') даст True
See also
Open in the full glossarydocs.python.orgReport an inaccuracy