-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrecord.py
47 lines (33 loc) · 815 Bytes
/
record.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
from collections import OrderedDict
class Record:
def __init__(self):
self.__dict__['_inner'] = OrderedDict()
def __setattr__(self,k,v):
self.__dict__['_inner'][k] = v
def __getattr__(self,k):
return self.__dict__['_inner'][k]
def __setitem__(self,k,v):
self.__dict__['_inner'][k] = v
def __getitem__(self,k):
return self.__dict__['_inner'][k]
def items(self):
return self._inner.items()
def as_dict(self):
return self.__dict__['_inner']
def as_list(self):
return self.__dict__['_inner']
ls = []
for k,v in self.items():
ls.append((k,v))
return ls
@classmethod
def from_dict(Cls, kvs):
r = Cls()
r.__dict__['_inner'] = kvs
return r
@classmethod
def from_list(Cls, kvs):
r = Cls()
for k,v in kvs.items():
r[k] = v
return r