forked from srbcheema1/my_scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
data_bank.py
35 lines (27 loc) · 813 Bytes
/
data_bank.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
import pickle
import os
class filer:
def __init__(self,file_name):
self.file_name = file_name
if not os.path.exists(file_name):
fout = open(file_name,'wb')
self.data = dict()
pickle.dump(self.data,fout)
fout.close()
self.load()
def load(self):
self.data = pickle.load(open(self.file_name,'rb'))
return self.data
def __getitem__(self,index):
if(index in self.data):
return self.data[index]
else:
return False
def __setitem__(self,index,value):
self.data[index]=value
def __contains__(self,value):
return value in self.data
def get(self):
return True
def save(self):
pickle.dump(self.data,open(self.file_name,'wb'))