Método Python File truncate()
Ejemplo
Abra el archivo con "a" para agregar, luego trunque el archivo a 20 bytes:
f = open("demofile2.txt", "a")
f.truncate(20)
f.close()
#open
and read the file after the truncate:
f = open("demofile2.txt", "r")
print(f.read())
Definición y uso
El truncate()
método cambia el tamaño del archivo al número dado de bytes.
Si no se especifica el tamaño, se utilizará la posición actual.
Sintaxis
file.truncate(size)
Valores paramétricos
Parameter | Description |
---|---|
size | Optional. The size of the file (in bytes) after the truncate. Default None, which means the current file stream position. |