File Handling 15: Delete word in file

# Delete a word in a file

fs = open("ipt.txt", "r+")
search_str = input("Enter string to search : ").strip()

Line = fs.read()
Line = Line.replace(search_str, "")

fs.seek(0,0)
fs.truncate()
fs.write(Line)

fs.seek(0,0)
Line = fs.read()
print(Line)

fs.close()

No comments:

Post a Comment

Don't be a silent reader...
Leave your comments...

Anu