In python:
open('file.txt', 'w').close()
Or alternatively, if you have already an opened file:
f = open('file.txt', 'r+')
f.truncate(0) # need '0' when using r+
More Related Contents:
- How to dynamically create variable names? Or should I simply use a dictionary?
- How can I iterate over files in a given directory?
- How do I create a list of random numbers without duplicates?
- Converting integer to string in Python
- Setting different color for each series in scatter plot on matplotlib
- Any way to clear python’s IDLE window?
- What’s an efficient way to find if a point lies in the convex hull of a point cloud?
- Calling the “source” command from subprocess.Popen
- How to set the timeout of ‘driver.get’ for python selenium 3.8.0?
- How to completely remove Python from a Windows machine?
- Generate permutations of list with repeated elements
- How do I check if stdin has some data?
- What is the difference between pandas.qcut and pandas.cut?
- ROC for multiclass classification
- Block tridiagonal matrix python
- Existence of mutable named tuple in Python?
- Python Threading String Arguments
- Check if two Python functions are equal
- Flask-SQLAlchemy db.create_all() raises RuntimeError working outside of application context
- How do I make a single legend for many subplots?
- What does the argument mean in fig.add_subplot(111)?
- Can not increment global variable from function in python [duplicate]
- How to add a background image into pygame?
- Python: setting two variable values separated by a comma in python
- f.read coming up empty
- Is there a way to implement methods like __len__ or __eq__ as classmethods?
- python_2_unicode_compatible error
- Iterate a list with indexes [duplicate]
- How to display charts in Spyder
- How to fix error “ERROR: Command errored out with exit status 1: python.” when trying to install django-heroku using pip [duplicate]