TEXT FILE PROGRAMS
# Program to count the no.of 'a'
f = open("notes.txt",'r')
str = f.read()
c = str.count('a')
print(c)
f.close()
# to print the number of "do"
f = open("notes.txt",'r')
str = f.read()
L =str.split()
print(L.count("do"))
f.close()
# to count the number of lines starting with 'A'
f = open("notes.txt",'r')
str = f.readlines()
count = 0
for i in str:
if i[0] == "A" :
count += 1
print(count)
f.close()
# program to print the last line from the text file
fo = open("gv.txt","r")
s = fo.readlines()
l= len(s)
print(s[l-1])
fo.close()
# Program to read data from binary file
import pickle
with open("sai.dat","rb") as fo:
L = pickle.load(fo)
for i in L:
print(i)
# Program to count the no.of 'a'
f = open("notes.txt",'r')
str = f.read()
c = str.count('a')
print(c)
f.close()
# to print the number of "do"
f = open("notes.txt",'r')
str = f.read()
L =str.split()
print(L.count("do"))
f.close()
# to count the number of lines starting with 'A'
f = open("notes.txt",'r')
str = f.readlines()
count = 0
for i in str:
if i[0] == "A" :
count += 1
print(count)
f.close()
# program to print the last line from the text file
fo = open("gv.txt","r")
s = fo.readlines()
l= len(s)
print(s[l-1])
fo.close()
# Program to read data from binary file
import pickle
with open("sai.dat","rb") as fo:
L = pickle.load(fo)
for i in L:
print(i)