-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBinary_file_operations.py
76 lines (71 loc) · 1.78 KB
/
Binary_file_operations.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#Search
def search():
e= input("Enter field to be serached [NAME,CLASS,SEC,AGE] ->")
k=input("Enter char ->")
while True:
try:
s=pickle.load(f)
if s[e]==k:
print(s,"Data found in file...")
except EOFError:
break
#Replace
def rep():
while True:
try:
s=pickle.load(f)
print(s,"\n","Change required?[y/n]...")
u=input()
if u.lower()==y:
e= input("Enter field to be changed [Name,Class,Section,Age](be case sensetive...) ->")
k=input("Enter change ->")
d[e]=k
pickle.dump(d,f)
except EOFError:
print("Ran out of data...")
break
#Adding new entries
def add():
while True:
d={}
n=input("Enter name ->")
c=int(input("Enter class ->"))
s=input("Enter section ->")
a=int(input("Enter age ->"))
d['Name']=n
d['Class']=c
d['Section']=s
d['Age']=a
pickle.dump(d,f)
r=input("Do you want to contnue [y/n]")
if r.lower() == 'n':
break
#Reading entries
def read():
while True:
try:
s=pickle.load(f)
print(s)
except EOFError:
print("Ran out of data...")
break
#Main
import pickle
f=open("Bintrash.dat","ab+")
while True:
print("1.Search \n 2.Replace \n 3.Adding new entries \n 4.Read entries \n 5.Exit")
o=input()
if o=='1':
search()
elif o=='2':
rep()
elif o=='3':
add()
elif o=='4':
read()
elif o=='5':
print('Thanks for using our service...')
f.close()
break
else:
print("Wrong input")