Created
September 30, 2013 14:24
-
-
Save vrld/6764579 to your computer and use it in GitHub Desktop.
Lua-Table like dictionary for Python
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 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