Fork me on GitHub
#uuid不会啊
import pickle
import uuid
class School:
name_school='oldboy'
def __init__(self, name, address):
self.uuid=uuid.uuid4()
self.sch_name=name
self.sch_address=address
self.classes = []

def tell_sch_info(self):
print('学校信息:校区:%s 地址:%s' %(
self.sch_name,
self.sch_address
))

def related_class(self,schcla_obj):
self.classes.append(schcla_obj)

def tell_class(self):
self.tell_sch_info()
for schcla_obj in self.classes:
schcla_obj.tell_scs_info()

# sch_obj1=School('上海','虹桥')
# sch_obj2=School('上海','张江')
# sch_obj3=School('北京','五道口')
# sch_obj1.tell_sch_info()
# sch_obj2.tell_sch_info()
# sch_obj3.tell_sch_info()

class SchoolClass:

def __init__(self,name):
self.uuid = uuid.uuid4()
self.schcla_name = name
self.course=[]

def related_course(self, cou_obj):
self.course.append(cou_obj)

def tell_scs_info(self):
print('班级名称:%s' % (
self.schcla_name,
))
for cou_obj in self.course:
cou_obj.tell_course_info()

# schcla_obj1=SchoolClass('python十一期')
# schcla_obj2=SchoolClass('python十二期')
# sch_obj1=School('上海','虹桥')
# sch_obj1.related_class(schcla_obj1)
# sch_obj1.related_class(schcla_obj2)
# sch_obj1.tell_class()

class Course:

def __init__(self, name,price,cycle):
self.uuid = uuid.uuid4()
self.cou_name=name
self.cou_price=price
self.cou_cycle=cycle
self.cou_teach=[]

def related_teach(self, tea_obj):
self.cou_teach.append(tea_obj)

def tell_course_info(self):
print('课程信息:名字:%s 价格:%s 周期:%s' %(
self.cou_name,
self.cou_price,
self.cou_cycle
))
for tea_obj in self.cou_teach:
tea_obj.tell_info()

# cou_obj1=Course('Python',20000,6)
# cou_obj2=Course('Linux',20000,6)
# sch_obj1=School('上海','虹桥')
# schcla_obj1=SchoolClass('python十一期')
# sch_obj1.related_class(schcla_obj1)
# schcla_obj1.related_course(cou_obj1)
# schcla_obj1.related_course(cou_obj2)
# sch_obj1.tell_class()

class Teacher:
school_teach='oldboy'

def __init__(self, x,y,z):
self.uuid = uuid.uuid4()
self.tea_age=x
self.tea_salary=y
self.tea_level=z

def tell_info(self):
print('教师信息:名字:%s 薪资:%s 等级:%s' %(
self.tea_age,
self.tea_salary,
self.tea_level
))

# tea_obj1=Teacher('lxx',20000,6)
# tea_obj2=Teacher('egon',50000,10)
# tea_obj3=Teacher('tank',20000,6)
#
# sch_obj1=School('上海','虹桥')
# schcla_obj1=SchoolClass('python十一期')
# cou_obj1=Course('Python',20000,6)
# sch_obj1.related_class(schcla_obj1)
# schcla_obj1.related_course(cou_obj1)
# cou_obj1.related_teach(tea_obj1)
# cou_obj1.related_teach(tea_obj2)
# cou_obj1.related_teach(tea_obj3)
# sch_obj1.tell_class()

class Student:

def __init__(self,name,age,gender,number):
self.stu_name=name
self.stu_age=age
self.stu_gender=gender
self.stu_number=number
self.course = None

def related_school(self, sch_obj):
self.course=sch_obj

def tell_stu_info(self):
print('学生信息:名字:%s 年龄:%s 性别:%s 学号:%s' %(
self.stu_name,
self.stu_age,
self.stu_gender,
self.stu_number
))
self.course.tell_class()

stu1_obj=Student('tank',18,'male',111)
stu2_obj=Student('lili',19,'female',222)
stu3_obj=Student('jack',20,'male',333)

tea_obj1=Teacher('lxx',20000,6)

sch_obj1=School('上海','虹桥')
schcla_obj1=SchoolClass('python十一期')
cou_obj1=Course('Python',20000,6)
stu1_obj.related_school(sch_obj1)
sch_obj1.related_class(schcla_obj1)
schcla_obj1.related_course(cou_obj1)
cou_obj1.related_teach(tea_obj1)
stu1_obj.tell_stu_info()

with open('student.pickle', 'wb') as f1:
pickle.dump(stu1_obj.tell_stu_info(), f1)

with open('student.pickle', 'rb') as f2:
info=pickle.load(f2)

print(info)
posted on 2020-04-08 20:08  OBOS  阅读(143)  评论(0编辑  收藏  举报