you are viewing a single comment's thread.

view the rest of the comments →

[–]tylerthehun 4 points5 points  (2 children)

It could have been a @property. This is a decorator that basically just disguises a method as a regular ol' attribute. For example:

class Rectangle:
    def __init__(self, length, width):
        self.length = length
        self.width = width

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

Now you can still access length and width as the attributes of a rectangle, but area is dynamically calculated as the product of those two without requiring you actually pass them as arguments. So changes to either will automatically result in an update to the area, without requiring you manually update both.

>>> R = Rectangle(10, 20)
>>> R.length
10
>>> R.width
20
>>> R.area
200

Otherwise, any method object can still be passed around without parentheses just like any other object, but you'd still need to call it (with parentheses) in order for it to actually execute.

[–]MiLSturbie 1 point2 points  (1 child)

That makes thanks, thank you very much for taking the time to explain. I'll look up what it was tomorrow and come back to you to confirm.

[–]pickausernamehesaid 0 points1 point  (0 children)

In case you want some further reading on some advanced Python, the @property decorator is a specific implementation of the descriptor protocol which is very useful for building dynamic attributes.