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

os.lstat

Prev: os.listdir | Up: os | Next: os.makedirs
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.lstat
Tags: #public #python3 #stdlib #os


Import

import os
from os import lstat

Signature & Overview

os.lstat(path, *, dir_fd=None)

Perform a stat system call on the given path, without following symbolic links.

Usage

import os
import stat
from pathlib import Path
import tempfile

with tempfile.TemporaryDirectory() as tmp:
    target = Path(tmp) / "t.txt"
    target.write_text("x", encoding="utf-8")
    link = Path(tmp) / "l.txt"
    link.symlink_to(target)
    assert stat.S_ISLNK(os.lstat(link).st_mode)

Gotchas

REPL Inspect

from os import lstat
help(lstat)

Linked from

Related notes