'''Practical No. 10: WAP in Python to create a text file and remove
the lines which contains the letter 'K'.'''
import sys
f=open("sps.txt","w+")
print("Enter the lines/data to insert in the file: ")
data = sys.stdin.readlines()
for i in data:
f.write(i)
f.close()
print("**********")
print("Content of File: ")
f=open("sps.txt","r")
data=f.read()
print(data)
f.close()
f=open("sps.txt","r+")
data=f.readlines()
f.seek(0)
for i in data:
if "K" not in i:
f.write(i)
f.truncate()
f.close()
print("**********")
print("Content of File After Deletion: ")
f=open("sps.txt","r")
data=f.read()
print(data)
No comments:
Post a Comment