On this page
os.dup
Prev: os.DirEntry | Up: os | Next: os.dup2
Rel: os.abort, os.access, os.chdir, os.chmod
Ref: docs.python.org — os.dup
Tags: #public #python3 #stdlib #os
Import
import os
from os import dup
Signature & Overview
os.dup(fd, /)
Return a duplicate of a file descriptor.
Usage
import os
r_fd, w_fd = os.pipe()
r_dup = os.dup(r_fd)
try:
assert r_dup != r_fd
finally:
os.close(r_dup); os.close(r_fd); os.close(w_fd)
Gotchas
- Creates a new fd pointing to the same open file description: Both fds share the same file offset and flags; both must be closed.
REPL Inspect
from os import dup
help(dup)
Linked from
Related notes
- tuts/python3/stdlib_module/os/DirEntry Linked here; links to this page; shared tags: #os, #stdlib
- tuts/python3/stdlib_module/os/dup2 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