Skip to content

Instantly share code, notes, and snippets.

@vrld
Created September 30, 2013 14:24
Show Gist options
  • Save vrld/6764579 to your computer and use it in GitHub Desktop.
Save vrld/6764579 to your computer and use it in GitHub Desktop.
Lua-Table like dictionary for Python
class Table(dict):
def __getattr__(self, name):
return self[name] if name in self else None
def __setattr__(self, name, value):
if value is not None:
self[name] = value
elif name in self:
del self[name]
def __delattr__(self, name):
self.__setattr__(name, None)
d = Table()
d.foo = 'bar'
print d.foo # bar
d.foo = None # = del d.foo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment