-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDictionary Module.py
49 lines (41 loc) · 1.08 KB
/
Dictionary Module.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
#this function helps 'unlock and lock' dictionaries in python
#you would need to enter a boolean value for the lock and unlock functions
#the class that holds all the commands
class dict_control:
def __init__(self, d):
self.d = d
self.b = True
self.j = d
def unlock(self):
self.b = True
def lock(self):
self.b = False
self.d = {}
def access(self):
if not self.b:
return '\u001b[31mAccess Denied\u001b[0m'
else:
self.d = self.j
return self.d
def stat(self):
if not self.b:
return 'LOCKED'
else:
return 'UNLOCKED'
#main/test code
if __name__ == '__main__':
exDictionary = {
'john': 'fluffy',
'jan' : 'greg'
}
dictionary = dict_control(exDictionary)
dictionary.lock()
print(dictionary.access())
print(dictionary.stat())
dictionary.unlock()
print(dictionary.access())
print(dictionary.stat())
if dictionary.stat() == 'LOCKED':
print('False')
else:
print('True')