On this page
posix.ftruncate
Prev: posix.fsync | Up: posix | Next: posix.get_blocking
Rel: posix.abort, posix.access, posix.chdir, posix.chflags
Ref: docs.python.org — posix.ftruncate
Tags: #public #python3 #stdlib #posix
Import
import posix
from posix import ftruncate
Signature & Overview
posix.ftruncate(fd, length, /)
Truncate a file, specified by file descriptor, to a specific length.
Usage
import os, tempfile
with tempfile.TemporaryFile('w+b') as f:
f.write(b'abcdef')
f.flush()
os.ftruncate(f.fileno(), 3)
f.seek(0)
assert f.read() == b'abc'
Gotchas
- Truncates or zero-extends an open file without moving the file cursor.
REPL Inspect
from posix import ftruncate
help(ftruncate)
Linked from
Related notes
- tuts/python3/stdlib_module/posix/fsync Linked here; links to this page; shared tags: #posix, #stdlib
- tuts/python3/stdlib_module/posix/get_blocking Linked here; links to this page; shared tags: #posix, #stdlib
- tuts/python3/stdlib_module/posix Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/posix/abort Linked here; shared tags: #posix, #stdlib
- tuts/python3/stdlib_module/posix/access Linked here; shared tags: #posix, #stdlib
- tuts/python3/stdlib_module/posix/chdir Linked here; shared tags: #posix, #stdlib
- tuts/python3/stdlib_module/posix/chflags Linked here; shared tags: #posix, #stdlib
- tuts/python3/stdlib_module/posix/chmod shared tags: #posix, #stdlib
- tuts/python3/stdlib_module/posix/chown shared tags: #posix, #stdlib
- tuts/python3/stdlib_module/posix/chroot shared tags: #posix, #stdlib