Created
July 1, 2014 07:06
-
-
Save mayflaver/bcd5c6e8e329d4780509 to your computer and use it in GitHub Desktop.
__getattr__ vs property
This file contains 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 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