Skip to content

Instantly share code, notes, and snippets.

@pylemon
Created May 5, 2012 10:50
Show Gist options
  • Save pylemon/2601515 to your computer and use it in GitHub Desktop.
Save pylemon/2601515 to your computer and use it in GitHub Desktop.
python: sqlstorage dict orm
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