Shelve of data storage for Students ' course selection system

Source: Internet
Author: User

Project Catalog:

#bin/run.pyfrom core.main Import runrun.login ()
#core/adm.py#-*-coding:utf-8-*-__author__ = ' mrchu ' import hashlibimport shelve#shelve={' Student ': [{' name ': ' xxx ', ' PassWord ': ' xxx ', ' course ': []},{...},{...}], # ' Administrators ': [{' name ': ' xxx ', passWord ': ' xxx '},{...},{        ...}], # ' Course ': [' xxx ', ' xxx ', ' xxx ']class GetMd5: #MD5加密 @classmethod def get_md5 (self,msg): MD5=HASHLIB.MD5 (b ' [email protected]#$%^&* ') #加盐 md5.update (Msg.encode (' Utf-8 ')) return md5.hexd Igest () class Course: #课程类 all_course_list=[] #所有课程列表 @classmethod def add_new_course (cls,course): Course.all _course_list.append (Course) class Administrators: #管理员类 def __init__ (self,name,pwd): #管理员初始化方法 self.adm_list=[] #管理员 Account List self.stu_list=[] #学生账号列表 self.name=name# account self.pwd=pwd# password self.gongneng_list =[' new_cours E ', ' new_student ', ' show_all_course ', ' show_all_student ', ' Show_all_stu_course '] #功能列表 def login (self,name,pwd): # Administrator Login method #读取管理员信息文件 f = shelve. Open (R '). /db/data ', writeback=true) self.adm_list = f[' Administrators '] self.stu_list = f[' Student '] course.al        L_course_list = f[' course '] # print (self.stu_list) f.close () dic={} dic[' name '] = Name            dic[' PassWord ']=getmd5.get_md5 (PWD) if DIC in self.adm_list: #拼接传入的name和加盐的pwd, compare with file data print (' Login successful ') Self.main_run () #运行管理员主程序方法 else:print (' Login failed, re-enter ') def main_run (self): #管理员主程序方法 prin            T (' Welcome to Administrator Course Maintenance system ') while 1:print (' 1. Create course ') print (' 2. Create student account number ') print (' 3. View all courses ')            Print (' 4. View all students ') print (' 5. View all students ' Course selection ') num=input (' Please select the sequence number to operate (press Q to exit the maintenance system) >>> ') If num.upper () = = ' Q ': Break func=getattr (Self,self.gongneng_list[int (num)-1]) #反射通过输入的值运行相应的 Method func () def new_course (self): #创建新课程 f = shelve.open (R ').     /db/data ', writeback=true) # Read the student's file while 1:       Course=input (' Please enter new course (press Q to exit): ') if course.upper () = = ' Q ': Break if course in Co Urse.all_course_list: #如果输入课程在课程类全部课程列表中 print (' This course already available ') else:Course.add_new_cours E (course) #把课程添加到课程类全部课程列表中 f[' Course ']=course.all_course_list print (' Create course success ') F.close () def new_student (self): #创建新的学生对象 f = shelve.open (R '). /db/data ', writeback=true) # Read the student's file while 1:name=input (' Please enter create account (press Q to exit): ') if name.upper () = = '                    Q ': Break psd=input (' Please enter create password: ') for El in Self.stu_list: #遍历管理员类的学生账号列表                If name==el[' name ': #如果有此账号 print (' already has this account ') Break else: dic={} dic[' name ']=name dic[' PassWord ']=getmd5.get_md5 (PSD) dic[' Co           Urse ']=[] self.stu_list.append (DIC) #把学生账号添加入管理员类的学生账号列表     f[' Student ']=self.stu_list# append write student information file print (' Create Student Account Success ') F.close () def show_all_course (self): #显示所有课程方法 print (' Existing course: ') for El in Course.all_course_list:print (EL) def show_all_student (sel f): #显示所有学生方法 print (' All students have: ') for El in Self.stu_list:print (el[' name ') def show_all_stu_ Course (self): #显示所有学生的选课信息方法 print (' All students are selected as follows: ') for El in Self.stu_list:try:pri        NT (el[' name '],el[' Course ') except Keyerror as E:pass def zhuce (SELF,NAME,PSD): #注册管理员方法 #读取管理员信息文件 F=shelve.open (R ').                /db/data ', writeback=true) self.adm_list=f[' Administrators '] #把管理员账号放到管理员类的管理员账号列表 for El in Self.adm_list:            If name==el[' name ']: #判断账号是否存在 print (' This administrator already exists ') break else: #把新创建的管理员账号秘密追加写入管理员信息文件 dic = {} dic[' name '] =name dic[' PassWord ']=GETMD5.GET_MD5 (PSD) self.adm_list.append (DIC) f[' Administrators ']=self.adm_list print (' Gen Build Admin Account Success ') F.close ()
#core/main.py#-*-coding:utf-8-*-__author__ = ' mrchu ' import shelvefrom. Import stufrom. Import adm#shelve={' Student ': [{ ' name ': ' xxx ', ' passWord ': ' xxx ', ' course ': []},{...},{...}], # ' Administrators ': [{' name ': ' xxx ', ' PassWord ':        ' xxx '},{...},{...}], # ' Course ': [' xxx ', ' xxx ', ' xxx ']}class Run: @classmethod def login (self): While 1:print (' 1. Admin login ') print (' 2. Student login ') print (' 3. Registered Administrator account number ') num = Inpu                T ("Please select Login method (press ' Q ' to exit the program) >>>") if num.upper () = = ' Q ': Break if int (num) = = 1:                        While 1:name = input (' Please enter the login account (press Q to return to the main login page): ') if name.upper () = = ' Q ': Break pwd = input (' Please enter password: ') ad=adm. Administrators (NAME,PWD) func=getattr (AD, ' login ') func (name,pwd) elif int (num) ==2:while 1:namE = input (' Please enter login account (press Q to return to main login page): ') if name.upper () = = ' Q ': Break PWD = input (' Please enter password: ') stu=stu. Student (NAME,PWD) func=getattr (stu, ' login ') func (name,pwd) elif int (num)  = = 3:while 1:name = input (' Please enter a registered account (press Q to return to the main login page): ') if name.upper () = = ' Q ': Break pwd = input (' Please enter password ') ad = ADM. Administrators (name, pwd) func = getattr (AD, ' Zhuce ') func (name, pwd) if __name__== "_ _main__ ": Run.login ()
#core/stu.py#-*-coding:utf-8-*-__author__ = ' mrchu ' import hashlibimport shelve #shelve ={' Student ': [{' name ': ' xxx ', ' PassWord ': ' xxx ', ' course ': []},{...},{...}], # ' Administrators ': [{' name ': ' xxx ', passWord ': ' xxx '},{...},{    ...}], # ' Course ': [' xxx ', ' xxx ', ' xxx ']}class GetMd5: #MD5加密 @classmethod def get_md5 (self,msg): md5=hashlib.md5 (b ' [email protected]#$%^&* ') #加盐 md5.update (ms G.encode (' Utf-8 ')) return Md5.hexdigest () class Course: #课程类 all_course_list=[] #所有课程列表 @classmethod def add_ New_course (Cls,course): Course.all_course_list.append (Course) class Student: #学生类 def __init__ (self,name,pwd): #学生初 Initiation Method Self.name=name #学生账号 self.pwd=getmd5.get_md5 (pwd) #学生密码 self.course_list=[] #学生已选课程列表 self        . student=[] #学生字典组成的列表 [{' name ': ' xxx ', ' passWord ': ' xxx ', ' course ': []},{...},{...}] self.gongneng_list=[' Show_all_course ', ' choice_course ', ' Show_chioce_course ', ' Del_course '] #功能列表 def __str__ (self): #打印学生对象的方法 return ' Student account object ' def login (self,name,pwd): #学生登录方法 F = Shelve.open (R '). /db/data ', writeback=true) #读学生的文件 self.student=f[' student '] course.all_course_list = f[' Course '] fo R el in self.student:if name==el[' name ']and getmd5.get_md5 (pwd) ==el[' PassWord ']: for I in range  (Len (self.student)): If self.student[i][' name '] = = Self.name:self.course_list = f[' Student '][i][' Course '] f.close () print (' login successful ') Self.main_run () #运行 Main program method Break Else:print (' Login failed, re-enter ') def main_run (self): #主程序方法 print (' Welcome to Students ' selection course System ') while 1:print (' 1. View all courses ') print (' 2. Select Course ') Print (' 3. View selected Course ') print     (' 4. Delete selected Course ') num=input (' Please select the sequence number to operate (press Q to exit) >>> ') if num.upper () = = ' Q ': Break       FUNC=GETATTR (Self,self.gongneng_list[int (num)-1]) #反射通过输入的值运行相应的方法 func () def show_all_course (self): #显 Methods for all courses print (' Existing course: ') for El in Course.all_course_list: #遍历课程类的全部课程列表 print (EL) def Choice_c Ourse: #选课的方法 While 1:course = input (' Enter the course you want to select (press Q to exit): ') if course.upper () = = '                    Q ': Break If course in Course.all_course_list: #所选课程在课程类的全部课程列表中, optional lessons available                        If course in Self.course_list:print (' This course has been selected, cannot be selected repeatedly ') Else: Self.course_list.append (course) #把课程放到学生对象的已选课程列表 lst=[] for El in Self.s                                Tudent:if el[' name ']==self.name:dic={} dic[' name ']=self.name dic[' passWord ']=self.pwd dic[' Course ']=self.course_lisT Lst.append (DIC) Else:lst.appen D (el) F = shelve.open (R ').                        /db/data ', writeback=true) #读学生的信息 # Print (LST) f[' Student ']=lst F.close () print (' elective success ') Else:print (' No This course ') def SH Ow_chioce_course (self): #显示所选课程列表 print (' Your selected course has: ') for El in self.course_list: #遍历学生对象的已选课程列表 prin T (EL) def del_course (self): #删除学生已选课程列表的内容 while 1:course = input (' Please enter the course to be deleted (press Q to exit): ') if C Ourse.upper () = = ' Q ': Break If course in Self.course_list:self.course_list.remove (                        Course) LST = [] for El in Self.student:if el[' name '] = = Self.name:                       DIC = {} dic[' name '] = Self.name dic[' PassWord ' = self.pwd dic[' course '] = self.course_list lst.append (DIC) Else:lst.append (EL) f = shelve.open (R '). /db/data ', writeback=true) # Read the student's message # Print (LST) f[' Student '] = LST f.close ( Print (' delete succeeded ') Break Else:print (' No this course ')

Shelve of data storage for Students ' course selection system

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.