I am generally confused about the difference between a "property" and an "attribute", and I can’t find a great resource to concisely detail the differences.
I am generally confused about the difference between a "property" and an "attribute", and
Share
Properties are a special kind of attribute. Basically, when Python encounters the following code:
it looks up
eggsinSomeObject1, and then examineseggsto see if it has a__get__,__set__, or__delete__method — if it does, it’s a property, and Python will call the__get__method (since we were doing lookup) and return whatever that method returns. If it is not a property, theneggsis looked up inspam, and whatever is found there will be returned.More information about Python’s data model and descriptors.
1 Many thanks to Robert Seimer for the correction on the lookup sequence.