-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-student.py
executable file
·49 lines (41 loc) · 1.25 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/python3
"""
11-student module
Initiates Student class that defines a student
"""
class Student():
"""Student class
"""
def __init__(self, first_name, last_name, age):
"""Initialize instance attributes
Arguments:
first_name -- Student's first name
last_name -- Student's Last name
age -- Student's age
"""
self.first_name = first_name
self.last_name = last_name
self.age = age
def to_json(self, attrs=None):
"""convert the object to json object
Returns:
The JSON object
"""
attributes = {}
if type(attrs) is list:
for attr in attrs:
if type(attr) is not str:
return self.__dict__
for key in attrs:
if self.__dict__.get(key) is not None:
attributes.setdefault(key, self.__dict__.get(key))
else:
return self.__dict__
return attributes
def reload_from_json(self, json):
"""Replaces all attributes of the Student instance
Arguments:
json -- The new attributes dictionary
"""
for key, value in json.items():
setattr(self, key, value)