-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-student.py
37 lines (28 loc) · 999 Bytes
/
11-student.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/python3
""" Module that defines the class Student
"""
class Student:
""" Class to create student instances """
def __init__(self, first_name, last_name, age):
""" Special method to initialize """
self.first_name = first_name
self.last_name = last_name
self.age = age
def to_json(self, attrs=None):
""" Method that returns directory description """
obj = self.__dict__.copy()
if type(attrs) is list:
for item in attrs:
if type(item) is not str:
return obj
d_list = {}
for iatr in range(len(attrs)):
for satr in obj:
if attrs[iatr] == satr:
d_list[satr] = obj[satr]
return d_list
return obj
def reload_from_json(self, json):
""" Replaces all attributes of the Student instance """
for atr in json:
self.__dict__[atr] = json[atr]