def run(): """数据不存在时初始化db,初始化两个校区及三门课程""" if not os.path.exists(DB_DIR): write = shelve.open(DB_DIR) s_bj_obj = School('北京校区', '北京') s_sh_obj = School('上海校区', '上海') s_bj_obj.add_course('linux', '3个月', '8000') s_bj_obj.add_course('python', '4个月', '9000') s_sh_obj.add_course('go', '5个月', '10000') write['bj'] = s_bj_obj write['sh'] = s_sh_obj write.close() while True: user_choice = input('''\033[32;1m请输入您要登录的视图: 1 管理视图 2 教师视图 3 学生视图 q 退出学员管理系统 >>>\033[0m''') if user_choice == '1': ManageView() elif user_choice == '2': TeacherView() elif user_choice == '3': StudentView() elif user_choice == 'q': print("\033[33;1m感谢使用学员管理系统\033[0m") break else: print("\033[31;1m请输入正确的选项\033[0m")
def add_school(self): #添加学校 logging.info('开始添加学校') school_name = str(input("\033[1;35m请输入学校名称: \033[0m").strip()) if school_name in self.schooldata: print("\033[1;31m该学校已经创建。\033[0m") logging.error('该学校已经创建') else: school_addr = str(input("\033[1;35m请输入学校地址: \033[0m").strip()) self.schooldata[school_name] = School( school_name, school_addr) #将学校对象存储于school.db文件中,通过shelve存储模式 print("\033[1;32m学校添加成功。\033[0m") logging.info('学校添加成功')
def initialize(self): # 实例化两个校区北京上海 self.school_db = shelve.open(settings.school_db_file) self.school_db['北京'] = School('北京', '中国北京') self.school_db['上海'] = School('上海', '中国上海')
def initialize_school(self): self.school_db = shelve.open(settings.school_db_file) # 打开学校数据库文件 self.school_db['北京'] = School('北京', '中国.北京') self.school_db['上海'] = School('上海', '中国.上海')
def initialize_school(self): ##初始化两所学校 self.school_db = shelve.open(settings.school_db_file) self.school_db['北京'] = School('北京', '中国.北京') self.school_db['上海'] = School('上海', '中国.上海')
#!/usr/bin/python3 #@Author:CaiDeyang #@Time: 2018/9/11 23:38 import pickle import os import sys BaseDir = os.path.dirname(os.path.dirname(os.path.abspath(sys.argv[0]))) sys.path.append(BaseDir) from modules.school import School data = {} name = 'OldBoy北京校区' addr = '北京' bj_obj = School(name, addr) data[name] = bj_obj name = 'Oldboy上海校区' addr = '上海' sh_obj = School(name, addr) data[name] = sh_obj if __name__ == "__main__": with open('school.dat', 'wb') as db_f: pickle.dump(data, db_f)
def init_school(self): self.school_db = shelve.open(school_db_file) self.school_db['北京'] = School('北京', '北京市') self.school_db['上海'] = School('上海', '上海市')
def initialize_school(self): """实例化两个学校北京/上海""" self.school_db = shelve.open(settings.school_db_file) self.school_db['北京'] = School('北京', '中国.北京') self.school_db['上海'] = School('上海', '中国.上海')
def create_test_data(): schooldata = shelve.open(SCHOOL_DATADIR + "school.db",writeback = True) newschool1 = School("清华","北京") newschool2 = School("武大","武汉") newschool3 = School("川大","四川") newcourse1 = Course("java全站开发","5个月","20000元") newcourse2 = Course("python自动化运维","4个月","30000元") newcourse3 = Course("大数据","5个月","50000元") newteacher1 = Teacher("讲师马云A","123456","男","30","20000","13211114444") newteacher2 = Teacher("讲师马云B","123456","男","30","20000","13211114444") newteacher3 = Teacher("讲师马云C","123456","男","30","20000","13211114444") newteacher4 = Teacher("讲师马云D","123456","男","30","20000","13211114444") newteacher5 = Teacher("讲师马云E","123456","男","30","20000","13211114444") newgrade1 = Grade("1班","讲师马云A","java全站开发") newgrade2 = Grade("2班","讲师马云B","python自动化运维") newgrade3 = Grade("3班","讲师马云C","大数据") newstudent1 = Student("周杰伦1","123456","男","22","False") newstudent2 = Student("周杰伦2","123456","男","22","False") newstudent3 = Student("周杰伦3","123456","男","22","False") newstudent4 = Student("周杰伦4","123456","男","22","False") newstudent5 = Student("周杰伦5","123456","男","22","False") newstudent6 = Student("周杰伦6","123456","男","22","False") newstudent7 = Student("周杰伦7","123456","男","22","False") newstudent8 = Student("周杰伦8","123456","男","22","False") newstudent9 = Student("周杰伦9","123456","男","22","False") newgrade1.grade_student["周杰伦1"] = newstudent1 newgrade1.grade_student["周杰伦2"] = newstudent2 newgrade1.grade_student["周杰伦3"] = newstudent3 newgrade1.grade_student["周杰伦4"] = newstudent4 newgrade1.grade_student["周杰伦5"] = newstudent5 newgrade1.grade_student["周杰伦6"] = newstudent6 newgrade1.grade_student["周杰伦7"] = newstudent7 newgrade1.grade_student["周杰伦8"] = newstudent8 newgrade1.grade_student["周杰伦9"] = newstudent9 newschool1.school_course["java全站开发"] = newcourse1 newschool1.school_course["python自动化运维"] = newcourse2 newschool1.school_course["大数据"] = newcourse3 newschool1.school_grade["1班"] = newgrade1 newschool1.school_grade["2班"] = newgrade2 newschool1.school_grade["3班"] = newgrade3 newschool1.school_teacher["讲师马云A"] = newteacher1 newschool1.school_teacher["讲师马云B"] = newteacher2 newschool1.school_teacher["讲师马云C"] = newteacher3 newschool1.school_teacher["讲师马云D"] = newteacher4 newschool1.school_teacher["讲师马云E"] = newteacher5 schooldata["清华"] = newschool1 schooldata["武大"] = newschool2 schooldata["川大"] = newschool3 schooldata.close()
def init_school(self): sh = School('上海', '上海市') bj = School('北京', '北京市') data = {'上海': sh, '北京': bj} file_oper(school_db_file, 'wb', data)