import os
class Student():
def init(self,name,qq,phone):
self.name=name
self.qq=qq
self.phone=phone
def str(self):
return self.name+"\t"+str(self.qq)+"\t"+str(self.phone)
class StudentManager:
students=[];
@classmethod
def addStudent(cls):
name=input("please input name:")
qq=int(input("please input qq:"))
phone=int(input("please input phone:"))
student=Student(name,qq,phone)
cls.students.append(student);
@classmethod
def display(cls):
print("Name\tQQ\tPhone")
for student in cls.students:
print(student)
@classmethod
def delete(cls):
name=input("please input the name what you want delete:")
for student in cls.students:
if student.name==name:
cls.students.remove(student)
break
else:
print("there is not have the sutdent")
@classmethod
def update(cls):
name=input("please input the name what you want update")
for student in cls.students:
if student.name==name:
index=cls.students.index(student)
cls.students[index].name=input("Please input the new name:")
cls.students[index].qq=int(input("Please input your new qq:"))
cls.students[index].phone=int(input("Please input your new phone:"))
return
@classmethod
def read(cls):
a=os.path.exists('student.dat')
if a==True:
with open("student.dat","r") as f:
line=f.readline()
while(line!=''):
lines=line.rstrip().split(",")
student=Student(lines[0],lines[1],lines[2])
cls.students.append(student)
line=f.readline()
@classmethod
def write(cls):
with open("student.dat", "w") as f:
for student in cls.students:
f.write(student.name+","+str(student.qq)+","+str(student.phone)+"\n")
@staticmethod
def menu():
print("*"*30)
print("1:add")
print("2:display")
print("3:delete")
print("4:update")
print("5:exit")
print("*"*30)
@staticmethod
def run():
StudentManager.read()
while(True):
StudentManager.menu()
operator=input("please input your choice:")
if operator=="1":
StudentManager.addStudent()
if operator=="2":
StudentManager.display()
if operator=="3":
StudentManager.delete()
if operator=="4":
StudentManager.update()
if operator=="5":
StudentManager.write()
break
if name==“main”:
StudentManager.run()