all Python 3osfunction
os.read
os — file descriptors
Read up to n bytes from a file descriptor, returning bytes.
Syntax
os.read(fd, n)
It may return fewer than n bytes even if more data is coming — especially on pipes, sockets and terminals — so read in a loop. An empty b'' result means end of file. It works with bytes and bypasses Python's buffers; for everyday file work open() is more convenient.
Examples
import os
r, w = os.pipe()
os.write(w, b'hello')
print(os.read(r, 5)) # → b'hello'
os.close(r)
os.close(w)
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy