Created
May 5, 2012 10:50
-
-
Save pylemon/2601515 to your computer and use it in GitHub Desktop.
python: sqlstorage dict orm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SQLStorage(dict): | |
""" | |
a dictionary that let you do d['a'] as well as d.a | |
""" | |
def __getattr__(self, key): return self[key] | |
def __setattr__(self, key, value): | |
if self.has_key(key): | |
raise SyntaxError, 'Object exists and cannot be redefined' | |
self[key] = value | |
def __repr__(self): return '<SQLStorage ' + dict.__repr__(self) + '>' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment