class DataEntry(object): count = 0 def __init__(self, key=None, data=None): self.count += 1 if key is None: self.key = str(self.count) else: self.key = key if data is None: self.data = {} else: self.data = data.copy() def add_field(self, key, data): self.data[key] = data def get_field(self, key): return self.data[key] def __str__(self): rtn = '' rtn += 'Key: {}'.format(self.key) rtn += '\n{}'.format(self.data) return rtn def __repr__(self): return str(self) class DataStore(object): storeName = '.testdb.db' def __init__(self, name=None): if name is not None: self.storeName = name def get_entry(self,key): import shelve db = shelve.open(self.storeName) rtn = db[key] db.close() return rtn def store_entry(self,key,entry): import shelve db = shelve.open(self.storeName) d = DataEntry() d.add_field('fieldOne','SomeData') print d.get_field('fieldOne') print d
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question