On this page
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
- Does NOT follow symlinks: Unlike
os.stat(),os.lstat()inspects the symlink itself (even if its target is broken).
REPL Inspect
from os import lstat
help(lstat)
Linked from
Related notes
- tuts/python3/stdlib_module/os/listdir Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/makedirs Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/os/abort Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/access Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chdir Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chmod Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chown shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/close shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/cpu_count shared tags: #os, #stdlib