File Python truncate() Metodo
Esempio
Apri il file con "a" per aggiungere, quindi tronca il file a 20 byte:
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())
Definizione e utilizzo
Il truncate()
metodo ridimensiona il file al numero di byte specificato.
Se la dimensione non è specificata, verrà utilizzata la posizione corrente.
Sintassi
file.truncate(size)
Valori dei parametri
Parameter | Description |
---|---|
size | Optional. The size of the file (in bytes) after the truncate. Default None, which means the current file stream position. |