About my message:
>> ...  Nickel summary, lookup order is not dirt simple, and reading
>> and writing work differently.

David MacQuigg wrote:
Maybe I'm missing some subtleties, but it still seems simple to me.
> An attribute is looked up in the order object -> class -> superclasses,
> *UNLESS* that attribute happens to be a property of the class....
The subtleties involve the difference in the lookup order between
read-only properties and properties with a write method.

...
class Rectangle(object):
    def __init__(self, width, height):
        self.width = width
        self.height = height
#        self.area = width * height

    def getArea(self):
        return self.width * self.height
...

Written in later versions of Python (2.5 and up) as:
    class Rectangle(object):
        def __init__(self, width, height):
            self.width = width
            self.height = height
            # self.area = width * height

        @property
        def area(self):
            return self.width * self.height


--Scott David Daniels
scott.dani...@acm.org

_______________________________________________
Edu-sig mailing list
Edu-sig@python.org
http://mail.python.org/mailman/listinfo/edu-sig

Reply via email to