python班级管理系统代码_python练习---校园管理系统

#! /bin/env python#coding: utf-8

importpickleimporthashlibimportloggingfrom collections importOrderedDictfrom core.Mypickle importMypicklefrom core.Teacher importTeacherfrom core.Class importClassfrom core.Course importCoursefrom core.Student importStudentfrom core.School importSchoolfrom core importLogfrom conf importsettingsclassManager:

dic= OrderedDict([ ('创建学校','create_school'),

('创建学员', 'create_student'),

('创建讲师', 'create_teacher'),

('创建课程', 'create_course'),

('创建班级', 'create_class'),

('查看学校', 'show_school'),

('查看讲师', 'show_teacher'),

('查看班级', 'show_class'),

('查看课程', 'show_course'),

('退出', 'quit')])def __init__(self, name):

self.name=name

self.school_pickle=Mypickle(settings.schoolinfo)

self.teacher_pickle=Mypickle(settings.teacherinfo)

self.class_pickle=Mypickle(settings.classinfo)

self.student_pickle=Mypickle(settings.studentinfo)

self.course_pickle=Mypickle(settings.courseinfo)

self.obj=Log.Log()#创建学校

defcreate_school(self):

school_name= input('school name>').strip()

school_addr= input('school addr>').strip()

school_obj=School(school_name, school_addr)

self.school_pickle.dump(school_obj)

a= 'Create a school'self.obj.record(a)print('\033[1;31m学校创建成功!\033[0m')#创建课程

defcreate_course(self):

course_name= input('course name>').strip()

course_time= input('course time>').strip()

course_price= input('course price>').strip()#选择学校

self.show_school()

school_num= input('请输入课程所开设的校区序号:').strip()

school_obj=self.school_pickle.get_item(int(school_num))#创建一个属于课程的新对象

course_obj =Course(course_name,course_time,course_price)#将课程与学校绑定到一起

course_obj.school =school_obj#将课程对象dump写入courseinfo文件中

course_pickle =Mypickle(settings.courseinfo)

course_pickle.dump(course_obj)print('\033[1;31m课程创建成功!\033[0m')

a= 'Create a course'self.obj.record(a)#创建班级

defcreate_class(self):

class_name= input('class name>').strip()#关联课程

self.show_course()

course_num= input('请输入班级关联的课程序号:').strip()

course_obj=self.course_pickle.get_item(int(course_num))#关联讲师

self.show_teacher()

teacher_num= input('请输入班级关联的讲师序号:').strip()

teacher_obj=self.teacher_pickle.get_item(int(teacher_num))#创建一个属于班级的对象

class_obj =Class(class_name)

class_obj.course=course_obj

class_obj.teacher=teacher_obj

class_pickle=Mypickle(settings.classinfo)

class_pickle.dump(class_obj)print('\033[1;31m班级创建成功!\033[0m')

a= 'Create a class'self.obj.record(a)#创建学员账号

defcreate_student(self):

student_name= input('student name>').strip()

student_pwd= input('student password>').strip()

md5_obj= hashlib.md5(student_name.encode('utf-8'))

md5_obj.update(student_pwd.encode('utf-8'))

md5_passwd=md5_obj.hexdigest()

user= '%s|%s|%s\n' % (student_name,md5_passwd,'Student')

with open(settings.userinfo,'a',encoding='utf-8') as f:

f.write(user)#给学员选择学校

self.show_school()

school_num= input('请输入学生所在的校区序号:').strip()

school_obj=self.school_pickle.get_item(int(school_num))#创建一个属于学生的新对象

student_obj =Student(student_name)

student_obj.school=school_obj

student_pickle=Mypickle(settings.studentinfo)

student_pickle.dump((student_obj))print('\033[1;31m学生创建成功!\033[0m')

a= 'Create a student'self.obj.record(a)#创建讲师账号

defcreate_teacher(self):

teacher_name= input('teacher name>').strip()

teacher_pwd= input('teacher password>').strip()

md5_obj= hashlib.md5(teacher_name.encode('utf-8'))

md5_obj.update(teacher_pwd.encode('utf-8'))

md5_passwd=md5_obj.hexdigest()

user= '%s|%s|%s\n' % (teacher_name,md5_passwd,'Teacher')

with open(settings.userinfo,'a',encoding='utf-8') as f:

f.write(user)#给老师选择一个校区

self.show_school()

school_num= input('请输入老师所在的校区序号:').strip()

school_obj=self.school_pickle.get_item(int(school_num))#创建一个属于老师的新对象

teacher_obj =Teacher(teacher_name)#将老师选择的校区和老师对象绑定在一起

teacher_obj.school =school_obj#将老师对象dump进入teacherinfo文件

teacher_pickle =Mypickle(settings.teacherinfo)

teacher_pickle.dump(teacher_obj)print('\033[1;31m老师创建成功!\033[0m')

a= 'Create a teacher'self.obj.record(a)#查看学校

defshow_school(self):for num,school_obj in enumerate(self.school_pickle.load(),1):print(num,school_obj)print('')

a= 'View school information'self.obj.record(a)#查看讲师

defshow_teacher(self):for num,teacher_obj in enumerate(self.teacher_pickle.load(),1):print(num,teacher_obj)

a= 'View instructor information'self.obj.record(a)#查看学生

defshow_student(self):for num,student_obj in enumerate(self.student_pickle.load(),1):print(num,student_obj)

a= 'View student information'self.obj.record(a)#查看班级

defshow_class(self):for num,class_obj in enumerate(self.class_pickle.load(),1):print(num,class_obj)

a= 'View class information'self.obj.record(a)#查看课程

defshow_course(self):for num,course_obj in enumerate(self.course_pickle.load(),1):print(num,course_obj)

a= 'View course information'self.obj.record(a)defquit(self):print('\033[1;31m再见啦!!!\033[0m')

a= 'Program exits'self.obj.record(a)

exit()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值