-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdate.py
81 lines (74 loc) · 1.89 KB
/
Update.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
77
78
79
80
81
def UpStu():
import pickle
import os
import mysql.connector as db
con = db.connect(host="localhost", user="root", password="shriram", database="shriram")
cur = con.cursor()
SF = open("Student.dat", "rb")
TF = open("Temp.dat", "ab+")
AdmnNo = int(input("Enter the Admission Number of Student whose details are to be updated : "))
flag = 0
try:
while True:
L = pickle.load(SF)
if L[0] == AdmnNo:
L = pickle.load(SF)
print("Admission Number : ", L[0])
print("Name : ", L[1])
print("Class : ", L[2])
print("Section : ", L[3])
print("Gender : ", L[4])
print("DOB : ", L[5])
print("DOJ : ", L[6])
print("Stream :", L[7])
print("Phone Number : ", L[8])
print("Address : ", L[9])
D = L
print(D)
except EOFError or TypeError:
pass
searchq = "select * from student where AdmnNO={}".format(AdmnNo)
cur.execute(searchq)
rs = cur.fetchall()
if not rs:
print("No such Admission Number in the table!!")
else:
Name = input("Enter the correct student's name:")
DOB = input("Enter the correct date of birth:")
Address = input("Enter the correct Designation:")
query = "update student set Name='{}',DOB='{}',Address='{}' where AdmnNO={}".format(Name, DOB, Address, AdmnNo)
cur.execute(query)
print("Updation successful!")
con.commit()
con.close()
SF.close()
TF.close()
os.remove("Student.dat")
os.rename("Temp.dat", "Student.dat")
"""
if choice == "A" or choice == "a":
SF.seek(0)
while True:
L = pickle.load(SF)
if L[0] == AdmnNo:
Sec = input("Enter new Section : ")
L[3] = Sec.upper()
print(L)
pickle.dump(L, US)
flag = 1
else:
pickle.dump(L, US)
elif choice == "B" or choice == "b":
SF.seek(0)
while True:
L = pickle.load(SF)
if L[0] == AdmnNo:
PhNo = int(input("Enter New Phone Number : "))
L[6] = PhNo
pickle.dump(L, US)
flag = 1
else:
pickle.dump(L, US)
else:
print("Invalid Choice")"""
UpStu()