码迷,mamicode.com
首页 > 其他好文 > 详细

4/8

时间:2020-04-09 00:08:26      阅读:219      评论:0      收藏:0      [点我收藏+]

标签:ack   dump   mon   idt   style   enc   exp   clip   sel   

4/8

import uuid
import pickle
?
class Course:
    def __init__(self, name, period, price):
        self.name = name
        self.period = period
        self.price = price
        self.uuid = uuid.uuid4()
?
    def tell_course_info(self):
        print(f‘课程名:{self.name} 课程周期:{self.period} 课程价格:{self.price}‘)
?
    def write_info(self):
        with open(f‘{self.uuid}.pick‘, mode=‘wb‘) as f:
            pickle.dump(self, f)
?
?
class Class:
    def __init__(self, name):
        self.name = name
        self.course = None
        self.uuid = uuid.uuid4()
?
    def related_course(self, course_obj):
        self.course = course_obj
?
    def tell_class_info(self):
        # print(f‘班级名:{self.name} 课程名:{self.course}‘)
        print(f‘班级名:{self.name} ‘,end=‘ ‘)
        self.course.tell_course_info()
?
    def write_info(self):
        with open(f‘{self.uuid}.pick‘, mode=‘wb‘) as f:
            pickle.dump(self, f)
?
?
class School:
    def __init__(self, nickname, addr):
        self.nickname = nickname
        self.addr = addr
        self.classes = []
        self.uuid = uuid.uuid4()
?
    def related(self, class_obj):
        self.classes.append(class_obj)
?
    def tell_class_info(self):
        print(f‘校区:{self.nickname} ‘)
        for class_obj in self.classes:
            class_obj.tell_class_info()
?
    def write_info(self):
        with open(f‘{self.uuid}.pick‘, mode=‘wb‘) as f:
            pickle.dump(self, f)
?
?
?
?
school_obj1 = School(‘魔都校区‘, ‘上海‘)
school_obj2 = School(‘帝都校区‘, ‘北京‘)
?
class_obj1 = Class(‘脱产14期‘)
class_obj2 = Class(‘脱产15期‘)
?
course_obj1 = Course(‘python开发‘, ‘6mons‘, ‘20000‘)
course_obj2 = Course(‘linux‘, ‘5mons‘, ‘18000‘)
?
?
school_obj1.related(class_obj1)
school_obj2.related(class_obj2)

4/8

标签:ack   dump   mon   idt   style   enc   exp   clip   sel   

原文地址:https://www.cnblogs.com/bailongcaptain/p/12663963.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!