On this page
os.stat
Prev: os.scandir | Up: os | Next: os.stat_result
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.stat
Tags: #public #python3 #stdlib #os
Import
import os
from os import stat
Signature & Overview
os.stat(path, *, dir_fd=None, follow_symlinks=True)
Perform a stat system call on the given path.
Usage
import os
from pathlib import Path
import tempfile
with tempfile.TemporaryDirectory() as tmp:
p = Path(tmp) / "info.txt"
p.write_text("12345", encoding="utf-8")
st = os.stat(p)
assert st.st_size == 5
Gotchas
- Follows symlinks by default: Pass
follow_symlinks=False(or callos.lstat()) to inspect a symlink itself.
REPL Inspect
from os import stat
help(stat)
Linked from
Related notes
- tuts/python3/stdlib_module/os/scandir Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/stat_result 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