Skip to content

Commit 609421c

Browse files
author
Holladworld
committed
11 student file
1 parent a1fb044 commit 609421c

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/python3
2+
'''Module for class student'''
3+
4+
5+
class Student:
6+
'''Class that defines a student jsonification'''
7+
def __init__(self, first_name, last_name, age):
8+
'''Constructor'''
9+
self.first_name = first_name
10+
self.last_name = last_name
11+
self.age = age
12+
13+
def to_json(self, attr=None):
14+
"""Retrieves a dictionary"""
15+
if type(attr) is list and all(type(g) is str for g in attr):
16+
return {h: l for h, l in self.__dict__.items() if h in attr}
17+
else:
18+
return self.__dict__.copy()
19+
20+
def reload_from_json(self, json):
21+
'''Replaces all attributes of the Student instance'''
22+
for key, value in json.items():
23+
self.__dict__[key] = value
Binary file not shown.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"first_name": "John", "last_name": "Doe", "age": 23}

0 commit comments

Comments
 (0)