Professional Documents
Culture Documents
import pickle
f=open("emp.pickle","ab")
while True:
empid=int(input("ENTER EMPLOYEE ID:- "))
name=raw_input("ENTER EMPLOYEE NAME:- ")
desig=raw_input("ENTER EMPLOYEE DESIGNATION:- ")
sal=float(input("ENTER EMPLOYEE SALARY:- "))
dept=raw_input("ENTER EMPLOYEE DEPARTMENT:-")
l=[empid,name,desig,sal,dept]
pickle.dump(l,f)
choice=raw_input("DO YOU WANT TO ADD MORE RECORDS (PRESS y or n)")
if choice=='n'or choice=='N':
print("THANKS FOR ENTERING RECORD(S)")
break
f.close()
try:
while True:
l=pickle.load(f)
print l
except EOFError:
print("ALL RECORDS READ FROM FILE" )
f.close()
try:
while True:
l=pickle.load(f)
print "==============================================="
print "EMPLOYEE ID:-",l[0]
print "EMPLOYEE NAME:-",l[1]
print "EMPLOYEE DESINATION:-",l[2]
print "EMPLOYEE SALARY:-",l[3]
print "EMPLOYEE DEPARTMENT:-",l[4]
print "==============================================="
except EOFError:
print("ALL RECORDS READ FROM FILE" )
f.close()
except EOFError:
print("ALL RECORDS READ FROM FILE \n\nsorry " )
if found==0:
print "\nRECORD NOT FOUND"
f.close()
except EOFError:
print("ALL RECORDS COPIED TO empcopy.pickle FILE " )
f.close()
nf.close()
try:
while True:
l=pickle.load(f)
if l[3]>50000:
pickle.dump(l,nf)
except EOFError:
print("ALL RECORDS who are having salary more than 50000 COPIED TO sal.pickle FILE " )
f.close()
nf.close()
import pickle
import os
found=0
f=open("emp.pickle","rb")
nf=open("temp.pickle","wb")
eid=int(input("enter empid"))
try:
while True:
l=pickle.load(f)
if l[0]!=eid:
pickle.dump(l,nf)
else:
found=1
print("DETIALS OF RECORD DELETED")
print("===============================")
print "EMPID:-",l[0]
print "EMP NAME:-",l[1]
print "EMP DESIGNATION:-",l[2]
print "EMP SALARY:-",l[3]
print "EMP DEPARTMENT:-",l[4]
except EOFError:
if found==1:
print("=========RECORD DELETED=========")
else:
print("RECORD NOT FOUND")
f.close()
nf.close()
os.remove("emp.pickle")
os.rename("temp.pickle","emp.pickle")