Answers for "how to delete all content of a file in python"

11

python delete contents of file

f = open('file.txt', 'r+')
f.truncate(0)
Posted by: Guest on February-22-2020
0

python delete all data from file

file = open("sample.txt","r+")
file.truncate(0)
file.close()
Posted by: Guest on June-03-2020
5

python delete contents of file

open('file.txt', 'w').close()
Posted by: Guest on February-22-2020

Code answers related to "how to delete all content of a file in python"

Python Answers by Framework

Browse Popular Code Answers by Language