[Tutor] Python property()

daaku gee daaqou at gmail.com
Sat May 16 21:25:12 CEST 2015


I came across some code where 'property' is being used for class attributes
(or as a decorator @property)

    name = property(lambda self: getattr(self, '_data')['name'])

I think I understand what's going on here.  What I don't understand is
if/when to use property instead of a normal attribute.

1. Is 'property' used widely? Do you use it? Do you know of a github
project where I can look at the code using it? I am looking for more
examples.
2. Would you use it only when you need to validate or calculate the value
to be assigned to an attribute or is there any other place for 'property()'
to be used?
3. If there is value in learning and using property, kindly explain it or
point me to a document/writeup/book that I should read to get a better
understanding.

Thanks
d/


More information about the Tutor mailing list