Tough for me to find a good title for this problem. Please refer to code.
class School:
def __init__(self, info):
self.name = info['name']
self.student = info['students']
for x in self.student:
self.child[self.student[0]] = Child(x, self.student[x])
self.student[x] = Student(x, self.student[x])
class Student:
def __init__(self, student_info, student_id):
self.id = student_id
self.name = student_info[0]
self.age = student_info[1]
self.sex = student_info[2]
self.attendance = False
class Child(Student)
def __init__(self, student_info, student_id):
self.id = student_info[0]
self.student_id = student_id
schools = {1:{'name':'Hard Knocks', 'students':{1:['Tim',12,M], 2:['Kim',11,M]}}}
Pretty much I want to be able access the Student parameter 'attendance' using both the Student and Child object within the School instance.
#instantiating
for x in students:
schools[x] = School(schools[x])
schools[1].student[1].attendance = True
print schools[1].child['Tim'].attendance
I want the last line to print True since I set schools[1].student[1].attendance, but its printing False. How do I map it so when i set the child['Tim'] object, its the same as setting the student[1] object. student[1] and child['Tim'] should be mapped to the same Student object's parameter.
Is this even possible?