Skip to content

Instantly share code, notes, and snippets.

@taddeimania
Last active August 29, 2015 14:14
Show Gist options
  • Save taddeimania/328d6154af1fb49ba95b to your computer and use it in GitHub Desktop.
Save taddeimania/328d6154af1fb49ba95b to your computer and use it in GitHub Desktop.
# aside from the dict being vulnerable to overwrite what benefit does the @property give
# over the dict on the instance in this particular use case?
class MyClass(object):
@property
def my_attribute(self):
return {
'key': 'value'
}
my_dictionary = {
'key': 'value'
}
@mattjmorrison
Copy link

my_dictionary can be accessed on the class by doing MyClass.my_dictionary which you cannot do with my_attribute. my_dictionary can also be used as a global-ish scope shared by all instances of MyClass. I don't think there is a benefit of one over the other, they would just be used for different reasons.

@taddeimania
Copy link
Author

Thanks for clearing that up. I've seen a @class_property decorator in pytool for accessing the property on the class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment