On this page
  1. posix.ftruncate
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

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

REPL Inspect

from posix import ftruncate
help(ftruncate)

Linked from

Related notes