Python Glossary Русский

all Python 3osfunction

os.fstat

os — file descriptors

Return an os.stat_result for an open file descriptor.

Syntax

os.fstat(fd)

It describes the file that is actually open, even if it was renamed, deleted or replaced on disk since. That is why it guards against races: open first, then check with fstat, not the other way round. For a Python file object the same is os.fstat(f.fileno()).

Examples

import os
fd = os.open(os.__file__, os.O_RDONLY)
print(os.fstat(fd).st_size > 0)   # → True
os.close(fd)

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy