student_user.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
#file = user.db
class register():
print("开始注册新用户")
def __init__(self,user_name,user_password):
self.user_name = user_name
self.user_password = user_password
def register_user(user_name,user_password):
old_user_list = [user_name,user_password]
user_list = str(old_user_list)
# with open('user.db', 'r',encoding='utf-8') as file, open('newuser.db', 'w',encoding='utf-8') as newfile:
# for user_list in file:
# newfile.write(user_list.strip()+'
')
# else:
# newfile.write(user_list.strip()+'
')
# os.rename('user.db', 'user.db.bak')
# os.rename('newuser.db', 'user.db')
# os.remove('user.db.bak')
with open('user.pkl','rb') as file,open('newuser.pkl','wb') as newfile:
for user_list in file:
pickle.dump(user_list,newfile)
else:
pickle.dump(user_list, newfile)
os.rename('user.pkl','user.pkl.bak')
os.rename('newuser.pkl','user.pkl')
os.remove('user.pkl.bak')
#print(user_list)
#pickle.dump(user_list,file)
#pickle.dump(user_list,)
#user_dic = {}
#print(user_dic)
#print(user_list)
#print(user_name,user_password)
#def register_user(self,register_name,register_pwd):
# self
p = register
#p.register_user('Bruce',111)
p.register_user('Bruc67','dgdgf')
#p.register_user('Brucerrrr',111)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
class student(object):
"""学生类、包含姓名、年龄"""
def __init__(self,student_name,student_age):
self.student_name = student_name
self.student_age = student_age
class course():
"""定义课程,包含名称、价格、周期"""
def __init__(self,course_name,course_prise,course_time):
self.course_name = course_name
self.course_prise = course_prise
self.course_time = course_time
class Class(object):
"""班级类、包含名称、课程、学生"""
def __init__(self,class_name,course_obj):
self.class_name = class_name
self.class_course = course_obj
self.class_student = {} #学生字典 {学生名:学生实例}
class Teacher(object):
"""讲师类,定义teacher_name,teacher_salary,包含teacher_class"""
def __init__(self,teache_name,teacher_salary):
self.teacher_name = teache_name
self.teacher_salary = teacher_salary
self.teacher_class = []
def teacher_add__class(self,class_name,class_obj):
self.teacher_add__class[class_name] = class_obj
class school(object):
"""学校类,包含名称、地址、课程、班级、教师"""
def __init__(self,school_name,school_addr):
self.school_name = school_name
self.school_addr = school_addr
#self.school_course = {} #学校所有的课程实例 {"课程名“:课程实例}
#self.school_class = {}
#self.school_teacher = {} #类型与course一致
#self.school_student = {} #可扩展学生
def create_school(self):
print("学校名:【%s】 地址:【%s】" % (self.school_name, self.school_name))
if __name__== '__main__':
msg="""
欢迎来到巴伐利亚选课系统
1:登录系统
2:注册账号
3:退出系统
"""
menu_dic={
#'1':login,
#'2':Registered,
'3':exit,
}
while True:
print(msg)
choice = input('请选择>>:').strip()
if len(choice) == 0 or choice not in menu_dic:continue
if choice == 3: break