Método de arquivo Python truncate()
Exemplo
Abra o arquivo com "a" para anexar e trunque o arquivo para 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())
Definição e uso
O truncate()
método redimensiona o arquivo para um determinado número de bytes.
Se o tamanho não for especificado, a posição atual será usada.
Sintaxe
file.truncate(size)
Valores de parâmetro
Parameter | Description |
---|---|
size | Optional. The size of the file (in bytes) after the truncate. Default None, which means the current file stream position. |