Python Glossary Русский

Python 3.15+Linuxosterm

os.statx_result

os — filesystem

The result of os.statx: fields such as stx_size, stx_mtime and stx_btime. A field missing from stx_mask is None, not zero.

Syntax

st = os.statx(path, mask)
st.stx_size, st.stx_btime, st.stx_mask

Field names start with stx_, as in the system call: stx_size is the size, stx_mtime and stx_mtime_ns the modification time, stx_btime the creation (birth) time. The main difference from os.stat_result is an honest “no data”: if the kernel or filesystem did not return a field, there is None instead of a plausible zero, and a field may come back even when the mask did not ask for it. Check the field for None before use, or test stx_mask against the relevant STATX_* constant.

Examples

import os
with open('demo.txt', 'w') as f:
    f.write('hello')
st = os.statx('demo.txt', os.STATX_SIZE)
print(type(st).__name__, st.stx_size)  # → statx_result 5
has_btime = bool(st.stx_mask & os.STATX_BTIME)
print(has_btime == (st.stx_btime is not None))  # → True — поле есть, только если бит в stx_mask

See also

Open in the full glossarydocs.python.orgReport an inaccuracy