import re
#individual word search then whole line delete
with open("put.txt", "r") as f :
lst = f.readlines()
for i, j in enumerate(lst) :
if re.search(".*Dhaka.*", j) :
lst[i] = ""
with open("put.txt", "w") as f :
f.writelines(lst)
#individual line delete
print("\nEnter Line Number :: ")
n = int(input())
with open("put.txt", "r") as f :
lst = f.readlines()
for i, j in enumerate(lst) :
if i == n-1 :
lst[i] = ""
with open("put.txt", "w") as f :
f.writelines(lst)
#All File Data Delete
with open("put.txt", "r") as f :
lst = f.readlines()
for i, j in enumerate(lst) :
lst[i] = ""
with open("put.txt", "w") as f :
f.writelines(lst)
Comments
Post a Comment