all Python 3osfunction
os.fdopen
os — file descriptors
Wrap a file descriptor in a Python file object (like open()).
Syntax
os.fdopen(fd, mode)
The file object takes ownership of the descriptor: closing the object closes the descriptor, so do not call os.close afterwards. Pass closefd=False to keep the descriptor alive. It is essentially open(fd, ...) and takes the same parameters — mode, encoding, buffering.
Examples
import os
fd = os.open(os.__file__, os.O_RDONLY)
f = os.fdopen(fd)
print(hasattr(f, 'read')) # → True
f.close()
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy