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()