• 作业 4/9


    import uuid
    import pickle
    import os
    # 功能部分:
    #      校区创建完毕后,可以为每个校区创建班级
    
    def save(obj,path1):
        path1 = os.path.join(path1,'{}_{}.pkl'.format(obj.uid,obj.name))
        with open(path1, 'wb') as f:
            pickle.dump(obj, f)
    class School():
        def __init__(self,name,adr):
            self.uid = uuid.uuid3(uuid.NAMESPACE_DNS,name)
            self.name = name
            self.adr = adr
            self.classes_uid = []
        def add_class(self,class_obj):
            self.classes_uid.append(class_obj.uid)
        def look_school(self):
            print(self.name.center(50,'='))
            for classw in self.classes_uid:
                if os.path.exists('{}.pkl'.format(classw)):
                    while os.path.getsize('{}.pkl'.format(classw)):
                        with open('{}.pkl'.format(classw),'rb') as f:
                            class1 = pickle.load(f)
                        class1.look_class()
                        break
    
    
    
    class Class():
        def __init__(self,name):
            self.uid = uuid.uuid3(uuid.NAMESPACE_DNS,name)
            self.name = name
            self.courses_uid = []
            self.students = []
        def add_course(self,course_obj):
            self.courses_uid.append(course_obj.uid)
        def look_class(self):
            print(self.name)
            for cou1 in self.courses_uid:
                if os.path.exists('{}.pkl'.format(cou1)):
                    while os.path.getsize('{}.pkl'.format(cou1)):
                        with open('{}.pkl'.format(cou1), 'rb') as f:
                            cou = pickle.load(f)
                        cou.look_course()
                        break
    
    
    #      班级创建完毕后,可以为每个班级创建课程
    #
    #      学生创建完毕后,学生可以选择班级
    class Course():
        def __init__(self,name,price,time):
            self.uid = uuid.uuid3(uuid.NAMESPACE_DNS,name)
            self.name = name
            self.price = price
            self.time = time
        def look_course(self):
            print('课程名称:{} 课程价格:{} 课程周期:{}'.format(self.name,self.price,self.time))
    
    
    
    class Person():
        def __init__(self,name,age,sex):
            self.__name = name
            self.__age = age
            self.__sex = sex
    
        @property
        def data(self):
            return self.__name,self.__age,self.__sex
    
        @property
        def name(self):  # obj1.name
            return self.__name
    
    
        @name.setter
        def name(self,name_new):
            if type(name_new) != str:
                return
            self.__name = name_new
    
        @property
        def age(self):  # obj1.name
            return self.__age
    
        @age.setter
        def age(self, age_new):
            if type(age_new) != int:
                return
            self.__age = age_new
    
    
        @property
        def sex(self):  # obj1.name
            return self.__sex
    
    
        @sex.setter
        def sex(self,sex_new):
            if type(sex_new) != str:
                return
            if sex_new.lower() not in ['male','female']:
                return
            self.__sex = sex_new
    
    
    
    class Student(Person):
        def __init__(self,name,age,sex):
            Person.__init__(self,name,age,sex)
            self.uid = uuid.uuid3(uuid.NAMESPACE_DNS,name)
            self.__classes = []
            self.__cores = None
    
        def choose_class(self,class_obj):
            self.__classes.append(class_obj.uid)
        def look_class(self):
            print(self.__classes)
    
    
    #      老师创建完毕后,可以为学生打分
    # student = Student('wl',24,'male')
    class Teacher(Person):
        def __init__(self,name,age,sex):
            Person.__init__(self,name,age,sex)
            self.uid = uuid.uuid3(uuid.NAMESPACE_DNS,name)
    
        def set_core(self,stu_obj,core):
            str_obj.__Student__cores = core
    
    
    
    
    
    
    
    
    
    
    
    
    
    class G():
        pass
    class F(G):
        pass
    class E(F):
        pass
    class D(G):
        pass
    class C(G):
        pass
    class B(C):
        pass
    class A(B,D,E):
        pass
    print(A.mro())
    
    # 学员视图层
    
    def register():
        user = input('name:').strip()
        pwd = input('password:').strip()
        re_pwd = input('re_password:').strip()
        if pwd == re_pwd:
            #  接口层
            age = input('age:').strip()
            sex = input('sex:').strip()
            if age.isdigit():
                student = Student(user,int(age),'male')
                stu_data = {'user':user,'pwd':pwd}
                save(student,os.path.dirname(__file__))
                with open('students.txt','a',encoding='utf-8') as f:
                    f.write(str(stu_data) + '
    ')
                with open('{}.pkl'.format(user),'wb') as f:
                    pickle.dump(student.uid,f)
    def log_in():
        user = input('user:').strip()
        pwd = input('password:').strip()
        # 接口层
        with open('student.pkl','rb') as f:
            data = pickle.load(f)
            print(data)
    def choose_class():
        pass
    
    def pay():
        pass
    
    func_dic = {
        '0':['注册学员',register],
        '1':['登录学员',log_in],
        '2':['选择班级',choose_class],
        '3':['交钱',pay],
    }
    def student_mode():
        while True:
            for i in range(len(func_dic)):
                print('{} {}'.format(i,func_dic[str(i)][0]))
            choice = input('cmd:').strip()
            if choice not in func_dic:
                print('no cmd')
                continue
            func_dic[choice][1]()
    
    # student_mode()
    
    with open('students.txt','r',encoding='utf-8') as f:
        data = f.readline()
        print(data)
    with open('wltxt','rb') as f:
        data = pickle.load(f)
        print(type(data))
    
  • 相关阅读:
    elementui中el-alert实现换行的方法
    Element-UI中el-table实现简单动态数据绑定的实现
    腾讯课堂多倍速、去除xxx正在观看
    Linux vim 常用操作
    尚硅谷《谷粒商城项目总结》
    Centos 安装 Harbor
    centos 7 安装 kubernetes
    Mac VirtualBox 没有 Host-Only 选项怎么设置?
    VirtualBox 安装 centos7
    ssh 使用 sed 替换的时候,替换的字符串有单双引号的时候怎么用
  • 原文地址:https://www.cnblogs.com/pythonwl/p/12668457.html
Copyright © 2020-2023  润新知