标签:ack dump mon idt style enc exp clip sel
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)
标签:ack dump mon idt style enc exp clip sel
原文地址:https://www.cnblogs.com/bailongcaptain/p/12663963.html