Text file


#1

how do i remove text from a file?


#2

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


#3

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
f.close()

For Python 3.5 documentation, see open.


#4

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