zoukankan      html  css  js  c++  java
  • day29作业

    # 作业一:自己试验一下菱形问题下的属性查找顺序
    class G(object):
        def test(self):
            print('from G')
    
    class E(G):
        def test(self):
            print('from E')
    
    class F(G):
        def test(self):
            print('from F')
    
    class B(E):
        def test(self):
            print('from B')
    
    class C(F):
        def test(self):
            print('from C')
    
    class D(G):
        def test(self):
            print('from D')
    
    class A(C, B, D):
        pass
    
    print(A.mro())
    # [<class '__main__.A'>, <class '__main__.C'>,
    # <class '__main__.F'>, <class '__main__.B'>,
    # <class '__main__.E'>, <class '__main__.D'>,
    # <class '__main__.G'>, <class 'object'>]
    
    # 作业二:在昨天作业的基础之上
    # #    1、引入属性访问控制+property
    # #    2、引入继承与派生的概念来减少代码冗余
    #         注意:要满足什么"是"什么的关系,不满足"是"的关系不要去继承
    import uuid
    import pickle
    class N_id:
         uuid = uuid.uuid4()
         def __init__(self,uuid,name):
             self.n_id = uuid
             self.name = name
         def save(self):
             with open(f"{self.n_id}{self.name}.pkl", "w", encoding="utf-8")as f:
                 pickle.dump(self, f)
    
         def open(self):
             with open(f"{self.n_id}{self.name}.pkl", "r", encoding="utf-8")as f:
                 data = pickle.load(f)
                 print(data)
    
    class School(N_id):
        re_name = "老男孩培训"
        uuid = uuid.uuid4()
        def __init__(self,address,uuid,name):
            self.address = address
            N_id.__init__(self,uuid,name)
            self.class_lis = []
    
        def class_act(self,class_obj):
            self.class_lis.append(f"{class_obj.n_id}{class_obj.name}")
        @property
        def show_shcool(self):
            print(self.name)
            for i in self.class_lis:
                with open(f"{i}.pkl","w",encoding="utf-8")as f:
                    data = pickle.load(f)
                    print(data)
    
    class Class(N_id):
        def __init__(self,name):
            N_id.__init__(self,uuid,name)
            self.course_lis = None
    
        def course_act(self,course_obj):
            self.course_lis = f"{course_obj.n_id}{course_obj.name}"
    
        @property
        def show_class_info(self):
            print("%s"%self.name,end="")
            with open(f"{self.course_lis}.pkl", "r", encoding="utf-8")as f:
                data = pickle.load(f)
                print(data)
    
    class Course(N_id):
        def __init__(self,uuid,name,date,price):
            N_id.__init__(self,uuid,name)
            self.date = date
            self.price = price
    
        @property
        def show_course(self):
            print("名字%s,周期%s,价格%s"%(self.name,self.date,self.price))
    
    class Student(N_id):
        def __init__(self,uuid,name,age,id,sex):
            N_id.__init__(self,uuid,name)
            self.age = age
            self.id = id
            self.sex = sex
            self.class_choose = None
            self.score = None
    
        def choose(self,class_obj):
            self.class_obj = class_obj.n_id
    
    class Teacher(N_id):
        def __init__(self,uuid,name,age,salaery,level):
            N_id.__init__(self,uuid,name)
            self.age = age
            self.salaery = salaery
            self.level = level
            self.score = None
        def score_stu(self,score,stu_obj):
            self.score = score
            stu_obj.score = self.score
    
  • 相关阅读:
    A20 烧录和启动 log
    图像处理---图像分割技术---基于图像灰度分布的阈值方法一
    H.265---内容总览
    H.265---仿射运动模型和双线性运动模型
    H.265---帧内预测与帧间预测
    linux内核---进程通信---消息队列
    linux内核---嵌入式linux内核的五个子系统
    高并发服务器---nginx---实现负载均衡的几种方式
    高并发服务器---nginx---正向代理和反向代理
    【CV系列】基于形态学梯度的边缘检测
  • 原文地址:https://www.cnblogs.com/yding/p/12669842.html
Copyright © 2011-2022 走看看