-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontent.py
More file actions
34 lines (27 loc) · 763 Bytes
/
content.py
File metadata and controls
34 lines (27 loc) · 763 Bytes
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
#-*- coding: utf-8 -*-
import pickle
class Content:
def __init__(self):
self.contentTable = dict()
def get_content_num(self):
return len(self.contentTable)
def set(self, content):
#[TODO] get_content_num called too much
self.contentTable[self.get_content_num()] = content
current_index = self.get_content_num() - 1
return current_index
def get(self, id):
return self.contentTable.get(id)
def dump(self, file):
f = open(file, 'w')
pickle.dump(self.contentTable, f)
f.close()
def load(self, file):
f = open(file)
self.contentTable = pickle.load(f)
f.close()
def pretty_print(self):
for key, value in self.contentTable.iteritems():
print key
print "*****"
print value