Python Glossary Русский

all Python 3osfunction

os.write

os — file descriptors

Write bytes to a file descriptor, returning the number written.

Syntax

os.write(fd, data)

It may write only part of the data: the returned count can be less than the length, especially on non-blocking descriptors and pipes, so write the rest in a loop. There is no buffering — each call is a system call, so many small writes are slow.

Examples

import os
r, w = os.pipe()
print(os.write(w, b'hi'))   # → 2
os.close(r)
os.close(w)

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy