In [6]:
def stdentry(r,nam,c):# function to write a reord in file 'std.dat'
import pickle
f=open('std.bat','ab')
pickle.dump([r,nam,c],f)
f.close()
In [7]:
stdentry(1,'anukrati',12) #calling stdentry
In [8]:
stdentry(2,'prachi',12) #calling stdentry
In [9]:
stdentry(3,'agam',12) #calling stdentry
In [16]:
def stdshow(): # function designed for displaying all record of file std.bat
f=open('std.bat','rb')
import pickle
f.seek(0,2)
eof=f.tell()
f.seek(0,0)
while(f.tell()<eof):
d=pickle.load(f)
print(d)
f.close()
In [17]:
stdshow() #calling stdshow() to display all record
In [18]:
stdshow() #calling stdshow() to display all record
In [19]:
stdentry(4,'sonu',12) #calling stdshow() to display all record
In [20]:
stdshow() #calling stdshow() to display all record
In [21]:
def stdsearchnam(nam): # writing function for searching record by name
f=open('std.bat','rb')
import pickle
f.seek(0,2)
eof=f.tell()
f.seek(0,0)
while(f.tell()<eof):
d=pickle.load(f)
if(d[1]==nam):
print('my name is',d[1],'my rollno is',d[0],'and my class is',d[2])
f.close()
In [22]:
stdsearchnam('sonu') #calling of function for search in file by name sonu
In [24]:
stdsearchnam('agam') #calling of function for search in file by name agam
In [25]:
stdsearchnam('prachi') #calling of function for search in file by name prachi
In [37]:
def stdsearchnam(nam,nam1):
f=open('std.bat','rb+')
import pickle
f.seek(0,2)
eof=f.tell()
f.seek(0,0)
while(f.tell()<eof):
p=f.tell()
d=pickle.load(f)
if(d[1]==nam):
d=[d[0],nam1,d[2]]
f.seek(p,0)
pickle.dump(d,f)
f.close()
In [ ]: