Function Details: truncate

Description


Resize the stream to the given size in bytes (or the current position if size is not specified).


Extended Description


The truncate() method resizes the file to the given size. If size is not specified, it truncates the file at the current position. This method can be used to shrink or extend the size of the file. If extended, the contents of the new file area are undefined.


Function Signature



Module: io

Class: TextIOWrapper

Parameters



Parameter List


  • size: int

Return


Returns the new size of the file.


Return Type


int

Output

Explanation

This example truncates the file to 10 bytes. The file pointer remains at the end of the file.