Last active
August 29, 2015 14:14
-
-
Save taddeimania/328d6154af1fb49ba95b to your computer and use it in GitHub Desktop.
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
# 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' | |
} |
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
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.