Skip to content

Instantly share code, notes, and snippets.

@mayflaver
Created July 1, 2014 07:06
Show Gist options
  • Save mayflaver/bcd5c6e8e329d4780509 to your computer and use it in GitHub Desktop.
Save mayflaver/bcd5c6e8e329d4780509 to your computer and use it in GitHub Desktop.
__getattr__ vs property
class test(dict):
def __init__(self):
self['data'] = {}
def __setattr__(self, name, value):
self['data'][name] = value
def __getattr__(self, name):
try:
return self['data'][name]
except KeyError:
raise AttributeError(name)
@property
def foo(self):
return 'foos'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment