4/8
Posted bailongcaptain
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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的主要内容,如果未能解决你的问题,请参考以下文章