Menu
Newbedev LogoNEWBEDEV Python Javascript Linux Cheat sheet
Newbedev LogoNEWBEDEV
  • Python 1
  • Javascript
  • Linux
  • Cheat sheet
  • Contact

how to delete a files content in python code example

Example 1: clearing all text from a file in python

fileVariable = open('textDocName.txt', 'r+')
fileVariable.truncate(0)
fileVariable.close()

Example 2: how to delete everything on a file python

f = open('file.txt', 'r+')
f.truncate(0) # need '0' when using r+

Tags:

Python Example

Related

kivy download erorr exit status 1 mac code example ye5ygr iyjdlkgjdgjkitjlgktkholr,gk;fgktg'ghktfodetkhlfghmlthtrhtohjfrthkptkohykhkfyohkyohkyohykh code example prop types install code example jquery append to start code example check if character is a letter c++ code example nuxt custom page not found code example auth middleware in laravel is active code example reset to origin branch code example replacement for character python code example if statements with or java code example how to change value in dictionary c# code example mogodb populate code example

Recent Posts

Pandas how to find column contains a certain value Recommended way to install multiple Python versions on Ubuntu 20.04 Build super fast web scraper with Python x100 than BeautifulSoup How to convert a SQL query result to a Pandas DataFrame in Python How to write a Pandas DataFrame to a .csv file in Python
© 2021 newbedevPrivacy Policy