import pickle
Import the pickle class Base: DEF Save (self, address): with Open (address, ' WB ' ) AS F: # WB string write the pickle.dump (self, F) # Note that a representative example of the self itself class school (Base): DEF the __init__ (Self): the self.name = iNPUT ( ' enter the name of the new school% s: ' % I) self.addr = iNPUT ( ' enter address school% s: ' % I) class Lesson (Base): DEF __init__ (Self, name, School): self.name= Name self.school = School class Teacher (Base): DEF __init__ (Self, name, School, Lesson): self.name = name self.school = School self.lesson = Lesson msg = ' 1. Create a school \ the n- ' \ ' 2. Create course \ n- ' \ ' 3. Create teacher \ n- ' \ ' 4.exit \ n- ' s_info = [] l_info = [] I, J, K = 0,0,0 the while True: Print (MSG) Choice = INPUT ( ' Enter create content: ' ) IF Choice == ' . 1 ' : I = I +. 1 s_info.append (School ()) s_info [ I -1] .save ( ' School s.db% ' % I) # stored in the document school_obj the pickle.load = (Open ( ' School s.db% ' % I, ' RB ' )) Print (I, school_obj .addr) elif Choice == ' 2 ' : j=j+1 lesson_name=input('请输入课程%s名称:'%j) if lesson_name=='python' or lesson_name=='linux': l1=Lesson(lesson_name,pickle.load(open('school1.db','rb'))) l1.save('lesson%s.db'%j) print(j,l1.school.addr) elif lesson_name=='go' : L2 = Lesson (lesson_name, the pickle.load (Open ( ' school2.db ' , ' RB ' ))) l2.save ( ' Lesson s.db% ' % J) Print (J, l2.school.addr) the else : Print ( ' can only create python, linux, go three courses ' ) j = j-1 # If you enter the wrong j + 1 automatically, so it is necessary to make amendments j elif Choice == ' 3 ' : k = k + 1'd IF K> 2: Print ( ' as long as the two teachers ' ) Exit () the else : TEACHER_NAME = INPUT ( ' Enter the name of the teacher% s: ' % K) T = Teacher (TEACHER_NAME, the pickle.load (Open ( ' School s.db% ' % K, ' RB ' )), the pickle.load (Open ( ' Lesson s.db% ' % K, ' RB ' ))) t.save ( ' Teacher s.db% ' % K) Print (K, the pickle. Load (Open ( '% s.db Teacher ' % K, ' RB ' )). the __dict__ ) elif Choice == ' . 4 ' : Print ( ' Game over ' ) Exit () the else : Print ( ' Enter 1,2,3,4 \ n- ' )
》》》》》
1. Create a school
2. Create curriculum
3. Create teacher
4.exit
Please enter you need to create content: 1
Please enter the name of the new school 1: newboy
enter school 1 Address: shanghai
1 shanghai
1. Create a school
2. Create curriculum
3. Create teacher
4.exit
Please enter you need to create content: 1
Please enter the name of the new school 2: oldboy
enter school 2 Address: beijing
2 beijing
1. Create a school
2. Create curriculum
3. Create teacher
4.exit
Please enter you need to create content: 2
Enter the name Lesson 1: Python
1 shanghai
1. Create a school
2. Create curriculum
3. Create teacher
4.exit
Please enter the content to be created: linux
Please enter 1,2,3,4
1. Create a school
2. Create curriculum
3. Create teacher
4.exit
Please enter you need to create content: 2
Enter the name Lesson 2: Linux
2 shanghai
1. Create a school
2. Create curriculum
3. Create teacher
4.exit
Please enter you need to create content: 2
Enter the name Lesson 3: Go
3 beijing
1. Create a school
2. Create curriculum
3. Create teacher
4.exit
Please enter you need to create content: 2
Enter Lesson 4 Name: ada
only create python, linux, go three courses
1. Create a school
2. Create curriculum
3. Create teacher
4.exit
Please enter the content needs to be created: 3
Please enter the teacher 1 Name: SXJ
1 { 'name': 'SXJ', 'School': <__ main__.School Object AT 0x0388B6B0>, 'Lesson': <__ main __ Lesson Object AT 0x0388B730.> }
1. create a school
2. create curriculum
3. create teacher
4.exit
Please enter the content needs to be created: 3
Please enter the teacher 2 Name: Zyk
2 { 'name': 'Zyk', 'School': <__ main__.School Object AT 0x0388B5D0>, 'Lesson': <. __ main __ Lesson Object AT 0x0388B650> }
1. create a school
2. create curriculum
3. create teacher
4.exit
Please enter you need to create content: 3
as long as two teachers