0% found this document useful (0 votes)
12 views6 pages

Employee Data Management with Pickle

The document outlines various functions for managing employee data using Python's pickle module, including adding, displaying, updating, and deleting employee records. It provides specific functions to display employees based on criteria such as salary and job title, as well as to calculate average salaries. Additionally, it includes file handling operations for reading and writing employee data to binary files.

Uploaded by

gs2304249
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views6 pages

Employee Data Management with Pickle

The document outlines various functions for managing employee data using Python's pickle module, including adding, displaying, updating, and deleting employee records. It provides specific functions to display employees based on criteria such as salary and job title, as well as to calculate average salaries. Additionally, it includes file handling operations for reading and writing employee data to binary files.

Uploaded by

gs2304249
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

dump(): to write

load(): to read

import pickle
dump(): to write
load(): to read
File modes
wb
rb
ab
F=open(“[Link]”,”wb”)
F=open(“[Link]”,”rb”)

def add_data():
F=open("[Link]","wb")
while True:
ID=int(input("Enter Emp ID:"))
name=input("Enter Name:")
age=int(input("Enter Age:"))
gen=input("Enter Gender:")
job=input("Enter Job:")
sal=int(input("Enter Salary:"))
[Link]([ID,name,age,gen,job,sal],F)
choice=input("Do you want to enter more
records:")
if choice in "Nn":
break
[Link]()

#add_data()

def display_data():
F=open("[Link]","rb")
try:
while True:
E=[Link](F)
print(E)
except:
#print("End of file reached")

[Link]()

display_data()
"WAF to display the details of a particular
employee."

def Display():
F=open("[Link]","rb")
eid=int(input("Enter Employee Id:"))
try:
while True:
E=[Link](F)
if E[0]==eid:
print(E)
break
except:
print(eid,"Not Found")
[Link]()

"WAF to display the details of those employees


earning above 40000"
def Display():
F=open("[Link]","rb")
try:
while True:
E=[Link](F)
if E[5]>40000 :
print(E)
except:
[Link]()

"WAF to count the number of employees who are clerk"

def Display():
F=open("[Link]","rb")
A=0
try:
while True:
E=[Link](F)
if E[4]=="clerk":
A=A+1
except:
print("Total clerk:",A)
[Link]()

"WAF to calculate the average salary of clerk"


def Average():
F=open("[Link]","rb")
tsal=0
a=0
try:
while True:
E=[Link](F)
if E[4]=="clerk":
tsal=tsal+E[5]
a=a+1
except:

print("Average salary",tsal//a)
[Link]()

Average()

"WAF to copy the details of all the managers in


binary file [Link]"

def Copy():
FR=open("[Link]","rb")
FW=open("[Link]","wb")
try:
while True:
E=[Link](FR)
if E[4]=="Manager":
[Link](E,FW)
except:
[Link]()
[Link]()

"WAF to append more records in a binary file"

def Append():
F=open("[Link]","ab")
while True:
ID=int(input("Enter Emp ID:"))
name=input("Enter Name:")
age=int(input("Enter Age:"))
gen=input("Enter Gender:")
job=input("Enter Job:")
sal=int(input("Enter Salary:"))
[Link]([ID,name,age,gen,job,sal],F)
choice=input("Do you want to enter more
records:")
if choice in "Nn":
break
[Link]()

“WAF to delete the record of a particular employee”


def Delete():
FR=open("[Link]","rb")
FW=open("[Link]","wb")
try:
eid=int(input("Enter Emp ID to be deleted:"))
while True:
E=[Link](FR)
if E[0]!=eid:
[Link](E,FW)
except:
[Link]()
[Link]()
[Link]("[Link]")
[Link]("[Link]","[Link]")
“WAF to update the salary of a particular employee”

def Update():
FR=open("[Link]","rb")
FW=open("[Link]","wb")
try:
eid=int(input("Enter employee Id to be
updated:"))
while True:
E=[Link](FR)
if E[0]==eid:
E[5]=int(input("Enter New salary:"))
[Link](E,FW)
else:
[Link](E,FW)
except:
[Link]()
[Link]()
[Link]("[Link]")
[Link]("[Link]","[Link]")

You might also like