Filesystem and I/O Modules

stat

Interprets mode bits from os.stat() or os.lstat(). S_ISREG and S_ISDIR identify file types, while S_IMODE isolates permission and special mode bits. Mode bits do not necessarily describe every permission mechanism on every filesystem.

Formal Syntax & Structure

python syntaxpython
import stat

Return Value

module

Module namespace available through import; import is a statement, not a value-returning expression.

Working Example

Example Snippetpython
import statfrom pathlib import Pathfrom tempfile import TemporaryDirectorywith TemporaryDirectory() as folder:    path = Path(folder) / "data"    path.write_bytes(b"abc")    print(stat.S_ISREG(path.stat().st_mode))    print(path.stat().st_size)
Python Reference