-
Notifications
You must be signed in to change notification settings - Fork 0
/
dip.py
75 lines (54 loc) · 1.85 KB
/
dip.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import json
class TXTWriter:
def write(self, file_name: str, data: dict):
with open(file_name + ".txt", 'w') as txt_file:
txt_file.write(str(data))
class JSONWriter:
def write(self, file_name, data):
with open(file_name + ".json", "w") as json_file:
json_file.write(json.dumps(data))
class Group:
def __init__(self, name, students: list):
self.name = name
self.students = students
self.profile = {}
def save_profile(self, writer):
writer().write(self.name, self.profile)
def add_profile(self, **kwargs):
self.profile = {}
for elem in kwargs:
if elem not in self.profile:
self.profile[elem] = kwargs[elem]
else:
print(f'key {elem} is already in the profile')
class Student:
def __init__(self, name):
self.name = name
self.profile = {}
def save_profile(self, writer):
writer().write(self.name, self.profile)
def add_profile(self, **kwargs):
self.profile = {}
for elem in kwargs:
if elem not in self.profile:
self.profile[elem] = kwargs[elem]
else:
print(f'key {elem} is already in the profile')
class Teacher:
def __init__(self, name):
self.name = name
self.profile = {}
def add_profile(self, **kwargs):
self.profile = {}
for elem in kwargs:
if elem not in self.profile:
self.profile[elem] = kwargs[elem]
else:
print(f'key {elem} is already in the profile')
def save_profile(self, writer):
writer().write(self.name, self.profile)
# Test
test_student = Student('Jon')
test_student.add_profile(group='8b', faculty='Finance')
test_student.save_profile(TXTWriter)
test_student.save_profile(JSONWriter)