On this page
  1. genericpath.lexists
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

genericpath.lexists

Prev: genericpath.islink | Up: genericpath | Next: genericpath.samefile
Rel: genericpath.commonprefix, genericpath.exists, genericpath.getatime, genericpath.getctime
Ref: docs.python.org — genericpath.lexists
Tags: #public #python3 #stdlib #genericpath


Import

import genericpath
from genericpath import lexists

Signature & Overview

genericpath.lexists(path)

Test whether a path exists. Returns True for broken symbolic links

Usage

import os
from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    link = Path(tmp) / "broken"
    link.symlink_to(Path(tmp) / "missing_target")
    assert os.path.lexists(link) is True and os.path.exists(link) is False

Gotchas

REPL Inspect

from genericpath import lexists
help(lexists)

Linked from

Related notes