Text file


how do i remove text from a file?


To read or manipulate the text in the text.txt file you must first write in it .


Try this, and adapt it as necessary.

# Tested with Python 3.5    
# Use "w" to:
#   Create an empty file if it does not yet exist.
#   Empty the file if it does already exist.
f = open("text.txt", "w")

# If you want to add content, write to the file here.
# If you want it to remain empty, close it without writing to it.
# f.write("hello, world!")

# Close the file

For Python 3.5 documentation, see open.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.