Python

Python Menu

Python

Python File truncate() - Definition, Syntax, Parameters, Examples

Definition

The truncate() method resizes the file to the given number of bytes. If the size is not specified, the current position will be used.

Syntax

file.truncate(size)

Parameters

Parameter Description
size Optional. The size of the file (in bytes) after the truncate. Default None, which means the current file stream position.

Examples:

f = open("myFile.txt", "a")
f.truncate(20)
f.close()

Introduction

Python Basics

Python Advance

Data Science Python Tutorials

Python Functions and Methods