all Python 3osfunction
os.path.islink
os.path — existence and type checks
Check whether a path is a symbolic link (False if it does not exist).
Syntax
os.path.islink(path)
It looks at the path itself without following it: a broken link gives True. On Windows symlinks need privileges or developer mode, and islink does not recognise junction points — use isjunction for those. Where the system has no symlinks the function always returns False.
Examples
import os
print(os.path.islink('not_a_link_xyz')) # → False
print(os.path.islink(os.__file__)) # → False (обычный файл — не ссылка)
root = os.path.dirname(os.__file__)
print([n for n in os.listdir(root) if os.path.islink(os.path.join(root, n))]) # → список имён-ссылок в каталоге стандартной библиотеки, обычно []
print(os.path.lexists(os.__file__), os.path.islink(os.__file__)) # → True False (lexists отвечает «путь есть», islink — «это ссылка»; у битой ссылки exists даёт False, а islink — True)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy