DataFileHandling
DataFileHandling
def Countthis():
f=open("Read.txt",'r')
data=f.read()
word=data.split()#By default by space and return string into list
c=0
for i in word:
if i=='this' or i=='This':
c+=1
print(c)
Countthis()
2 #Write a function to read total no. of words of lenght>5 in a file
def Length():
f=open("Read.txt",'r')
data=f.read()
word=data.split()#By default split by space
#and return string into list
c=0
for i in word:
if len(i)>5:
c+=1
print(c)
Length()
3 #read file line by line and display number of line and each line
def count():
f=open("first.txt",'r')
c1=0
while True:
d=f.readline()
if d=='':#no space
break
else:
c1+=1
print(d)
print(c1)
count()
4 #read file line by line and display number of line starting with E and T
def BeginE():
f=open("first.txt",'r')
c=0
d=f.readlines()
for i in d:
if i[0]=='E' or i[0]=='T':
c+=1
print(i)
print(c)
BeginE()
#read file line by line and display line whose lenght is greater than 15
def count15():
f=open("first.txt",'r')
c=0
d=f.readlines()
for i in d:
if len(i)>15:
c+=1
print(i)
print(c)
count15()
5 WAP to write file using writelines
with open("sq.txt","w") as f:
d=["Computer Science","\nchemistry","\nPhysics"]
f.writelines(d)