On this page
os.fdopen
Prev: os.error | Up: os | Next: os.fork
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.fdopen
Tags: #public #python3 #stdlib #os
Import
import os
from os import fdopen
Signature & Overview
os.fdopen(fd, mode='r', buffering=-1, encoding=None, *args, **kwargs)
os.fdopen() function.
Usage
import os
r_fd, w_fd = os.pipe()
with os.fdopen(w_fd, "w", encoding="utf-8") as w, os.fdopen(r_fd, "r", encoding="utf-8") as r:
w.write("hello")
w.close()
assert r.read() == "hello"
Gotchas
- Takes ownership of the file descriptor: Closing the returned file object closes the underlying
fd(unlessclosefd=False).
REPL Inspect
from os import fdopen
help(fdopen)
Linked from
Related notes
- tuts/python3/stdlib_module/os/error Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/fork Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/os/abort Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/access Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chdir Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chmod Linked here; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/chown shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/close shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/cpu_count shared tags: #os, #stdlib