首页 > 代码库 > 周末作业:选课系统

周末作业:选课系统

角色:学校、学员、课程、讲师
要求:
1. 创建北京、上海 2 所学校
2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开
3. 课程包含,周期,价格,通过学校创建课程
4. 通过学校创建班级, 班级关联课程、讲师
5. 创建学员时,选择学校,关联班级
5. 创建讲师角色时要关联学校,
6. 提供三个角色接口
6.1 学员视图, 可以注册, 交学费, 选择班级,
6.2 讲师视图, 讲师可管理自己的班级, 上课时选择班级, 查看班级学员列表 , 修改所管理的学员的成绩
6.3 管理视图,创建讲师, 创建班级,创建课程
7. 上面的操作产生的数据都通过pickle序列化保存到文件里

初始目录结构:

技术分享

思维导图:

技术分享

技术分享

技术分享

技术分享
 1 # _*_ coding:utf-8 _*_
 2 import os,sys
 3 BASE_PATH=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
 4 sys.path.append(BASE_PATH)
 5 from src.core import *
 6 from conf.settings import *
 7 if __name__ == __main__:
 8     while True:
 9         print(‘‘‘************请选择************
10         1、学生界面
11         2、教师界面
12         3、管理员界面
13         ‘‘‘)
14         sel = input(>>>:).strip()
15         if sel == 1:
16             student_view()
17         elif sel == 2:
18             teacher_view()
19         elif sel == 3:
20             admin_view()
21         elif sel == q:
22             break
start.py
技术分享
  1 # _*_ coding:utf-8 _*_
  2 from src.models import *
  3 from conf.settings import *
  4 import os,pickle
  5 
  6 def file_dict(path):
  7     ‘‘‘传入路径,返回一个序号、名称、对象关联的字典‘‘‘
  8     dic={}
  9     n=0
 10     res = list(map(lambda x:(path+\\+x),os.listdir(path)))
 11     for i in res:
 12         with open(i,rb) as f :
 13             obj =pickle.load(f)
 14             n+=1
 15             dic[str(n)]=(obj.name,obj)
 16     return dic
 17 def login(identity):
 18     ‘‘‘登录验证身份‘‘‘
 19     if identity == student:
 20         PATH=STUDENTDB_PATH
 21     elif identity == teacher:
 22         PATH=TEACHERDB_PATH
 23     while True:
 24         user = input(login name:).strip()
 25         if user == q or user == Q:
 26             break
 27         pwd = input(password:).strip()
 28         if pwd == q or pwd ==Q:
 29             break
 30         all_peo = list(map(lambda x: x.split(.)[0], os.listdir(PATH)))
 31         m = hashlib.md5()
 32         m.update(user.encode(utf-8))
 33         id = m.hexdigest()
 34         # print(id)
 35         # print(all_stu)
 36         if id in all_peo:
 37             user_path = r%s\%s.pkl % (PATH, id)
 38             with open(user_path, rb) as f:
 39                 peo_obj = pickle.load(f)
 40                 if pwd == peo_obj._Person__pwd:
 41                     print(登录成功)
 42                     return peo_obj
 43                     # tag = False
 44                 else:
 45                     print(密码错误)
 46                     continue
 47         else:
 48             print(用户名错误)
 49             continue
 50 def get_course():
 51     while True:
 52         print(请按要求输入,输入q退出创建)
 53         name = input(name: ).strip().lower()
 54         price = input(price: ).strip().lower()
 55         period = input(period: ).strip().lower()
 56         if qin [name,price,period]:
 57             break
 58         cour = Course(name, price, period)
 59         cour.tell_course()
 60         confirm = input(确认提交请输入Y,重新填写请输入N:).strip().lower()
 61         if confirm == y:
 62             cour.save
 63             print(创建成功.center(17))
 64             break
 65         elif confirm == n:
 66             continue
 67 def get_school():
 68     while True:
 69         print(请按要求输入,输入q退出创建)
 70         name = input(name: ).strip().lower()
 71         address = input(adress: ).strip().lower()
 72         if q in [name, address]:
 73             break
 74         school = School(name, address)
 75         school.tell_info()
 76         confirm = input(确认提交请输入Y,重新填写请输入N:).strip().lower()
 77         if confirm == y:
 78             school.save
 79             print(创建成功.center(17))
 80             break
 81         elif confirm == n:
 82             continue
 83 def get_student():
 84     ‘‘‘user,pwd,name,age,sex,id_card‘‘‘
 85     while True:
 86         user = input(username: ).strip()
 87         pwd  = input(pasword: ).strip()
 88         name=input(name: ).strip()
 89         if not name:
 90             print(姓名不能为空)
 91             continue
 92         age=input(age: ).strip()
 93         if not age.isdigit():
 94             print(年龄需是整数)
 95             continue
 96         else:age=int(age)
 97         sex=input(sex: ).strip()
 98         if sex not in [male,female]:
 99             print(请输入正确的性别)
100             continue
101         id_card=input(id_card: ).strip()
102         if not id_card.isdigit():
103             print(请输入正确的身份证号码)
104             continue
105         break
106     s=Student(user,pwd,name,age,sex,id_card)
107     return s
108     # s.save
109 def get_teacher():
110     while True:
111         user = input(login name:).strip()
112         pwd = input(password:).strip()
113         name=input(name: ).strip()
114         if not name:
115             print(姓名不能为空)
116             continue
117         age=input(age: ).strip()
118         if not age.isdigit():
119             print(年龄需是整数)
120             continue
121         else:age=int(age)
122         sex=input(sex: ).strip()
123         if sex not in [male,female]:
124             print(请输入正确的性别)
125             continue
126         salary=input(salary: ).strip()
127         if not salary.isdigit():
128             print(请输入正确的薪资)
129             continue
130         level = input(level: ).strip()
131         if not level.isdigit():
132             print(请输入正确的教师等级)
133             continue
134         break
135     t=Teacher(user,pwd,name,age,sex,salary,level)
136     return t
137     # t.save
138 def get_team():
139     while True:
140         sch_dict = file_dict(SCHOOLDB_PATH)
141         print(<从下列学校中选择对应序号创建班级>)
142         for i in sch_dict:
143             print(i, sch_dict[i][0])
144         school = input(">>>:").strip()
145         if school == q: break
146         while True:
147             sch_obj = sch_dict[school][1]
148             team_dict = sch_obj.team
149             print(班级列表.center(len(team_dict) * 15, *))
150             for j, i in enumerate(team_dict, 1):
151                 print(j, i.name, end=  )
152             print()
153             name = sch_obj.name.split(_)[1] + _ + input(请输入新建班级名称:).strip()
154             confirm = input(确认提交请输入Y,重新填写请输入N:).strip().lower()
155             if confirm == y:
156                 team = Team(name)
157                 team.save
158                 print(创建成功.center(17))
159             elif confirm == n:
160                 continue
161             while True:
162                 cou_dict = file_dict(COURSEDB_PATH)
163                 print(请选择关联的课程\n******课程列表******)
164                 for i in cou_dict:
165                     print(i, cou_dict[i][0], end=  )
166                 print()
167                 courses = input(请选择要添加的课程序号(以空格分开):).strip().split()
168                 if len(courses)!=0 and set(courses).issubset(set(cou_dict.keys())):
169                     team.course.extend(list(map(lambda x: cou_dict[x][1], set(courses))))
170                     # print(team.course)
171                 else:
172                     print(请重新选择)
173                     continue
174                 confirm = input(确认提交请输入Y,重新填写请输入N:).strip().lower()
175                 if confirm == y:
176                     team.save
177                     break
178                 elif confirm == n:
179                     team.course.clear()
180                     continue
181             while True:
182                 tea_dict = file_dict(TEACHERDB_PATH)
183                 print(请选择关联的教师\n******教师列表******)
184                 for i in tea_dict:
185                     print(i, tea_dict[i][0], end=  )
186                 print()
187                 teacher = input(请选择要添加的教师序号(以空格分开):).strip().split()
188                 if len(teacher) != 0 and set(teacher).issubset(set(tea_dict.keys())):
189                     team.teacher.extend(list(map(lambda x: tea_dict[x][1], set(teacher))))
190                     # print(team.teacher)
191                 else:
192                     print(请重新选择)
193                     continue
194                 confirm = input(确认提交请输入Y,重新填写请输入N:).strip().lower()
195                 if confirm == y:
196                     team.save
197                     break
198                 elif confirm == n:
199                     team.teacher.clear()
200                     continue
201             team.tell_info()
202             #学校添加班级
203             for j,i in enumerate(sch_obj.team):
204                 if team.name == i.name:
205                     sch_obj.team.pop(j)
206             sch_obj.team.append(team)
207 
208 
209             #老师添加班级、课程
210             for tea_obj in team.teacher:
211                 for cou_obj in team.course:
212                     if cou_obj.name not in [ i.name for i in tea_obj.courses]:
213                         tea_obj.courses.append(cou_obj)
214 
215                 if team.name not in tea_obj.team:
216                     tea_obj.team.append(team.name)
217                 tea_obj.save
218                 for j,i in enumerate(sch_obj.teacher):
219                     if tea_obj.name == i.name :
220                         sch_obj.teacher.pop(j)
221                 sch_obj.teacher.append(tea_obj)
222 
223             for cou_obj in team.course:
224                 if cou_obj.name not in [i.name for i in sch_obj.courses]:
225                     sch_obj.courses.append(cou_obj)
226 
227             sch_obj.save
228             print(班级创建成功.center(17))
229             break
230         break
231 def class_manage():
232     while True:
233         team_dict = file_dict(TEAMDB_PATH)
234         print(班级列表.center(len(team_dict) * 15, *))
235         for i in team_dict:
236             print(i, team_dict[i][0], end=  )
237         print()
238         sel_t = input(选择序号查看详细信息(输入c进行创建班级,q退出):).strip().lower()
239         if sel_t in team_dict:
240             team_dict[sel_t][1].tell_info()
241         elif sel_t == c:
242             get_team()
243         elif sel_t == q:
244             break
245 def teacher_manage():
246     while True:
247         tea_dict = file_dict(TEACHERDB_PATH)
248         print(教师列表.center(len(tea_dict) * 15, *))
249         for i in tea_dict:
250             print(i, tea_dict[i][0], end=  )
251         print()
252         sel_t = input(选择序号查看详细信息(输入c进行创建老师,输入g关联学校,q退出):).strip().lower()
253         if sel_t in tea_dict:
254             tea_dict[sel_t][1].tell_info()
255         elif sel_t == c:
256             t = get_teacher()
257             t.save
258         elif sel_t == g:
259             while True:
260                 print(选择序号为该教师关联学校)
261                 for i in tea_dict:
262                     print(i, tea_dict[i][0], end=  )
263                 print()
264                 sel = input(>>>:).strip()
265                 if sel in tea_dict:
266                     tea_obj = tea_dict[sel][1]
267                     while True:
268                         sch_dict = file_dict(SCHOOLDB_PATH)
269                         print(学校列表.center(len(sch_dict) * 15, *))
270                         for i in sch_dict:
271                             print(i, sch_dict[i][0], end=  )
272                         print()
273                         sel_gs = input(选择要关联学校的序号\n>>>:).strip()
274                         if sel_gs in sch_dict:
275                             sch_obj = sch_dict[sel_gs][1]
276                             if sch_obj.name in tea_obj.school:
277                                 print(已关联该校区,请重新选择)
278                                 continue
279                             tea_obj.school.append(sch_obj.name)
280                             tea_obj.tell_info()
281                             confirm = input(确认提交请输入Y,重新填写请输入N:).strip().lower()
282                             if confirm == y:
283                                 tea_obj.save
284                                 sch_obj.teacher.append(tea_obj)
285                                 sch_obj.save
286                             elif confirm == n:
287                                 tea_obj.school.pop()
288                                 continue
289                         elif sel_gs == q:
290                             break
291                         break
292                 elif sel == q:
293                     break
294                 break
295         elif sel_t == q:
296             break
297 def student_view():
298     ‘‘‘登录、注册‘‘‘
299     while True:
300         print(‘‘‘************登录界面************
301             1、登录
302             2、注册
303         ‘‘‘)
304         sel_1 = input(>>>:).strip()
305         if sel_1 == 1:
306             obj = login(student)
307             while True:
308                 if obj == None:
309                     break
310                 print(‘‘‘************学生视图************
311             1、查看成绩
312             2、选择班级
313             3、缴纳学费
314             4、查看信息
315                 ‘‘‘)
316                 sel_2 = input(>>>:).strip()
317                 if sel_2 == 1:
318                     print(obj.score)
319                 elif sel_2 == 2:
320                     while True:
321                         # print(obj.school)
322                         sch_dict=file_dict(SCHOOLDB_PATH)
323                         # print(sch_dict)
324                         sch_obj=[sch_dict[i][1] for i in sch_dict if sch_dict[i][0] == obj.school[0]][0]
325                         # print(sch_obj)
326                         team_dict = sch_obj.team
327                         print(班级列表.center(len(team_dict) * 15, *))
328                         for j, i in enumerate(team_dict, 1):
329                             print(j, i.name, end=  )
330                         print()
331                         sel_t = input(>>>:).strip().lower()
332                         if sel_t == q:
333                             break
334                         if int(sel_t) - 1 in range(len(team_dict)):
335                             team_obj = team_dict[int(sel_t) - 1]
336                             if team_obj.name in obj.team:
337                                 print(已在该班级,请重新选择。)
338                                 continue
339                             obj.team.append(team_obj.name)
340                             for i in team_obj.course:
341                                 if i.name not in [i.name for i in obj.courses]:
342                                     obj.courses.append(i)
343                         obj.tell_info()
344                         confirm = input(确认提交请输入Y,重新填写请输入N:).strip().lower()
345                         if confirm == y:
346                             obj.save
347                             sch_obj.student.append(obj)
348                             sch_obj.save
349                             team_obj.student.append(obj)
350                             team_obj.save
351                             print(创建成功.center(17))
352                             break
353                         elif confirm == n:
354                             continue
355                 elif sel_2 == 3:
356                     while True:
357                         print(您的学费余额为:%s元%obj.fees)
358                         fee = input(请输入缴纳的学费金额:)
359                         obj.fees=int(fee)
360                         confirm = input(确认提交请输入Y,重新填写请输入N:).strip().lower()
361                         if confirm == y:
362                             obj.save
363                             print(缴费成功,您的学费余额为:%s元 % obj.fees)
364                             break
365                         elif confirm == n:
366                             continue
367                 elif sel_2 == 4:
368                     obj.tell_info()
369                 elif sel_2 == q:
370                     break
371         elif sel_1 == 2:
372             s = get_student()
373             while True:
374                 while True:
375                     print(请选择学校(输入序号))
376                     sch_dict = file_dict(SCHOOLDB_PATH)
377                     print(学校列表.center(len(sch_dict) * 15, *))
378                     for i in sch_dict:
379                         print(i, sch_dict[i][0], end=  )
380                     print()
381                     sel_s = input(>>>:).strip()
382                     if sel_s in sch_dict:
383                         sch_obj= sch_dict[sel_s][1]
384                         s.school.append(sch_obj.name)
385                         break
386                 while True:
387                     print(请选择班级(输入序号))
388                     team_dict = sch_obj.team
389                     print(班级列表.center(len(team_dict) * 15, *))
390                     for j, i in enumerate(team_dict, 1):
391                         print(j, i.name, end=  )
392                     print()
393                     sel_t = input(>>>:).strip()
394                     if int(sel_t)-1 in range(len(team_dict)):
395                         team_obj=team_dict[int(sel_t)-1]
396                         if team_obj.name in s.team:
397                             print(已在该班级,请重新选择。)
398                             continue
399                         s.team.append(team_obj.name)
400                         for cou_obj in team_obj.course:
401                             if cou_obj.name not in [i.name for i in s.courses]:
402                                 s.courses.append(cou_obj)
403                         break
404                 s.tell_info()
405                 confirm = input(确认提交请输入Y,重新填写请输入N:).strip().lower()
406                 if confirm == yor len(confirm) == 0:
407                     s.save
408                     sch_obj.student.append(s)
409                     sch_obj.save
410                     team_obj.student.append(s)
411                     team_obj.save
412                     print(创建成功.center(17))
413                     break
414                 elif confirm == n :
415                     s.school.pop()
416                     s.team.pop()
417                     continue
418         elif sel_1 == q:
419             break
420 def teacher_view():
421     obj=login(teacher)
422     while True:
423         if obj == None:
424             break
425         print(‘‘‘************讲师视图************
426         1、查看个人信息
427         2、班级信息管理‘‘‘)
428         sel_t=input(>>>:).strip()
429         if sel_t == 1:
430             obj.tell_info()
431         if sel_t == 2:
432             while True:
433                 team_dict={}
434                 n=0
435                 team=obj.team
436                 team_obj=file_dict(TEAMDB_PATH)
437                 for i in team_obj:
438                     if team_obj[i][0] in team:
439                         n+=1
440                         team_dict[str(n)]=team_obj[i]
441                 print(班级列表.center(len(team_dict) * 10, *))
442                 for i in team_dict:
443                     print(i, team_dict[i][0], end=  )
444                 print()
445                 sel_t = input(选择序号查看详细信息(q退出):).strip().lower()
446                 if sel_t in team_dict:
447                     while True:
448                         team_obj = team_dict[sel_t][1]
449                         team_obj.tell_info()
450                         print(********班级操作********\n   1、查看班级学员成绩)
451                         sel_b = input(>>>:)
452                         if sel_b == 1:
453                             while True:
454                                 print(学员成绩单)
455                                 for j,i in enumerate(team_obj.student,1):
456                                     print(j,i.name,i.score)
457                                 sel_s=input(请输入需要修改成绩的学生序号(q退出):).strip()
458                                 if sel_s == q or sel_s == Q:
459                                     break
460                                 elif int(sel_s)-1 <= len(team_obj.student):
461                                     while True:
462                                         stu_obj = team_obj.student[int(sel_s)-1]
463                                         for j,i in enumerate(team_obj.course,1):
464                                             print(j,i.name)
465                                         sel=input(选择科目的序号(q退出):).strip()
466                                         if sel == q or sel == Q:
467                                             break
468                                         if int(sel)-1 <=len(team_obj.course):
469                                             cou_obj = team_obj.course[int(sel)-1]
470                                             while True:
471                                                 score=input(请输入成绩:).strip()
472                                                 if 0<= int(score) <=100:
473                                                     stu_obj.score[cou_obj.name]=int(score)
474                                                 else:
475                                                     print(请输入0-100的整数)
476                                                     continue
477                                                 stu_obj.save
478                                                 for i in team_obj.student:
479                                                     if i.name == stu_obj.name:
480                                                         team_obj.student.remove(i)
481                                                 team_obj.student.append(stu_obj)
482                                                 team_obj.save
483                                                 break
484                                             break
485                         if sel_b == q:
486                             break
487                 elif sel_t == q:
488                     break
489         elif sel_t == q:
490             break
491 def admin_view():
492     ‘‘‘登录、注册‘‘‘
493     user = input(username:).strip()
494     pwd = input(password:).strip()
495     if user == admin and pwd == admin:
496         while True:
497             print(‘‘‘************管理视图************
498         1、讲师管理
499         2、班级管理
500         3、课程管理
501         4、校区管理
502                 ‘‘‘)
503             sel_2 = input(>>>:).strip().lower()
504             if sel_2 == 1:
505                 teacher_manage()
506 
507             elif sel_2 == 2:
508                 class_manage()
509 
510             elif sel_2 == 3:
511                 while True:
512                     cou_dict = file_dict(COURSEDB_PATH)
513                     print(课程列表.center(len(cou_dict)*10,*))
514                     for i in cou_dict:
515                         print(i, cou_dict[i][0], end=  )
516                     print()
517                     sel_c = input(选择序号查看详细信息(输入c进行创建课程,q退出):).strip().lower()
518                     if sel_c in cou_dict:
519                         cou_dict[sel_c][1].tell_course()
520                     elif sel_c == c:
521                         get_course()
522                     elif sel_c == q:
523                         break
524             elif sel_2 == 4:
525                 while True:
526                     sch_dict = file_dict(SCHOOLDB_PATH)
527                     print(学校列表.center(len(sch_dict)*15,*))
528                     for i in sch_dict:
529                         print(i, sch_dict[i][0], end=  )
530                     print()
531                     sel_s = input(选择序号查看详细信息(输入c进行创建校区,q退出):).strip().lower()
532                     if sel_s in sch_dict:
533                         sch_dict[sel_s][1].tell_info()
534                     elif sel_s == c:
535                         get_school()
536                     elif sel_s == q:
537                         break
538             elif sel_2 == q:
539                 break
core.py
技术分享
  1 # _*_ coding:utf-8 _*_
  2 #定义所有类
  3 from conf.settings import *
  4 import pickle
  5 import hashlib
  6 class Date:
  7     ‘‘‘时间类‘‘‘
  8     def __init__(self,year,mon,day):
  9         self.year=year
 10         self.mon=mon
 11         self.day=day
 12     def tell_birth(self):
 13         print(%s-%s-%s%(self.year,self.mon,self.day))
 14 class Course:
 15     ‘‘‘
 16     课程类:名称、价格、周期
 17     方法:打印课程信息 保存对象信息‘‘‘
 18     def __init__(self, name, price, period):
 19         self.name = name
 20         self.price = price
 21         self.period = period
 22     def tell_course(self):
 23         print(‘‘‘----------%s info----------
 24     course name:%s
 25     course price:%s
 26     course period:%s‘‘‘ % (self.name, self.name, self.price, self.period))
 27     @property
 28     def save(self):
 29         with open(r%s\%s.pkl%(COURSEDB_PATH,self.name),wb) as f:
 30             pickle.dump(self,f)
 31 class Person:
 32     ‘‘‘人类:名字、年纪、性别、课程 方法:打印课程、打印信息‘‘‘
 33     def __init__(self,user,pwd,name,age,sex):
 34         self.__user=user
 35         self.__pwd=pwd
 36         self.name=name
 37         self.age=age
 38         self.sex=sex
 39         self.school=[]      #存校区名字
 40         self.courses=[]     #存课程对象
 41         self.team = []      #存班级名称
 42         self.id = self.create_id()
 43     def create_id(self):
 44         m=hashlib.md5()
 45         m.update(self.__user.encode(utf-8))
 46         return m.hexdigest()
 47     def tell_course(self):
 48         for obj in self.courses:
 49             obj.tell_course()
 50     def tell_info(self):
 51         print(‘‘‘----------%s info ---------
 52         NAME:%s
 53         AGE: %s
 54         SEX: %s
 55         SCHOOL:%s
 56         COURSES:%s
 57         CLASS:%s‘‘‘ % (self.name, self.name, self.age, self.sex, self.school, [i.name for i in self.courses], self.team))
 58 class Teacher(Person):
 59     ‘‘‘
 60     老师类属性:名字、年纪、性别、薪资、等级、课程、班级
 61         方法:教书、打印信息、保存对象
 62     ‘‘‘
 63     def __init__(self,user,pwd,name,age,sex,salary,level):
 64         Person.__init__(self,user,pwd,name,age,sex)
 65         self.salary=salary
 66         self.level=level
 67     def teach(self):
 68         print(%s is teaching %self.name)
 69     def tell_info(self):
 70         Person.tell_info(self)
 71         print(‘‘‘        SAL: %s
 72         LEVEL:%s‘‘‘%(self.salary,self.level))
 73     @property
 74     def save(self):
 75 
 76         with open(r%s\%s.pkl%(TEACHERDB_PATH,self.id),wb) as f:
 77             pickle.dump(self,f)
 78 class Student(Person):
 79     ‘‘‘
 80     学生类:名字、年纪、性别、身份证号、班级、课程
 81       方法:学习、打印信息、保存对象
 82     ‘‘‘
 83     def __init__(self,user,pwd,name,age,sex,id_card):
 84         Person.__init__(self,user,pwd,name,age,sex)
 85         self.id_card=id_card
 86         self.fees=0
 87         self.score={}
 88     def study(self):
 89         print(%s is teaching %self.name)
 90     def tell_info(self):
 91         Person.tell_info(self)
 92         print(        ID:%s\n        FEES:%s\n        SCORE:%s % (self.id_card,self.fees,self.score))
 93     @property
 94     def save(self):
 95         with open(r%s\%s.pkl%(STUDENTDB_PATH,self.id),wb) as f:
 96             pickle.dump(self,f)
 97 class School:
 98     def __init__(self,name,address):
 99         self.name=name
100         self.address=address
101         self.courses=[]
102         self.team=[]
103         self.teacher=[]
104         self.student=[]
105     def tell_info(self):
106         print(‘‘‘----------%s info ---------
107         NAME:%s
108         ADDRESS: %s
109         TEACHER: %s
110         COURSES: %s
111          CLASS:  %s
112         SYUDENT:  %s
113         ‘‘‘ % (self.name, self.name, self.address, [i.name for i in self.teacher], [i.name for i in self.courses], [i.name for i in self.team], [i.name for i in self.student]))
114     @property
115     def save(self):
116         with open(r%s\%s%(SCHOOLDB_PATH,self.name),wb) as f:
117             pickle.dump(self,f)
118 class Team:
119     def __init__(self,name):
120         self.name=name
121         self.course=[]     #存课程对象
122         self.student=[]    #存学生对象
123         self.teacher=[]    #存老师对象
124     def tell_info(self):
125         print(‘‘‘----------%s info ---------
126           NAME : %s
127          COURSE: %s
128         TEACHER: %s
129         STUDENT: %s
130         ‘‘‘%(self.name,self.name,[i.name for i in self.course],[i.name for i in self.teacher], [i.name for i in self.student]))
131     @property
132     def save(self):
133         with open(r%s\%s % (TEAMDB_PATH, self.name), wb) as f:
134             pickle.dump(self, f)
models.py
技术分享
1 # _*_ coding:utf-8 _*_
2 import os,sys
3 BASE_PATH=os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
4 sys.path.append(BASE_PATH)
5 STUDENTDB_PATH=r%s\db\student%BASE_PATH
6 TEACHERDB_PATH=r%s\db\teacher%BASE_PATH
7 COURSEDB_PATH=r%s\db\course%BASE_PATH
8 SCHOOLDB_PATH=r%s\db\school%BASE_PATH
9 TEAMDB_PATH=r%s\db\team%BASE_PATH
settings.py

 

周末作业:选课系统