Binary File Program
Binary File Program
Write a program to create a BINARY file “Employee.dat” and insert the following data
into the file and perform the following task:
Eid Name Salary Age
E01 Aman 98000 34
E02 Shreya 87000 45
E03 Rahul 67000 23
E04 Rajesh 92000 67
import pickle
def write():
f=open("E:\Employee.dat","wb")
for i in range(4):
Eid=input("Enter Employee Id")
Name=input("Enter name")
Sal=float(input("Enter Salary"))
Age=input("Enter Age")
l=[Eid,Name,Sal,Age]
pickle.dump(l,f)
f.close()
def display():
f=open("E:\Employee.dat ","rb")
print("The content of the file:")
f=pickle.load(f)
for i in l:
print(*i)
f.close()
Display the Name of those Employee whose Age is more than 50.
def display1():
f=open("E:\Employee.dat ","rb")
f=pickle.load(f)
for i in l:
if i[3]>50:
print(*i)
f.close()
Display those content of the file whose name starting with R and ending with h.
def display1():
f=open("E:\Employee.dat ","rb")
f=pickle.load(f)
for i in l:
if i[1][0]=="R" and i[1][-1]=="h":
print(*i)
f.close()
def update():
f=open("E:\Employee.dat ","rb")
f=pickle.load(f)
for i in l:
if i[1]=”Aman”:
i[2]=i[2]*1.1
f.close()
f1=open("E:\Employee.dat ","wb")
pickle.dump(l,f1)
f1.close()
Delete those records of students from the file whose salary is more than 70000.
def delete():
f=open("E:\Employee.dat ","rb")
f=pickle.load(f)
m=[]
for i in l:
if i[2]<=70000:
m.append(i)
f.close()
f1=open("E:\Employee.dat ","wb")
pickle.dump(m,f1)
f1.close()
write()
display()
display1()
display2()
update()
display()
delete()
display()