Immutability

Fredrik Lundh fredrik at pythonware.com
Wed Jun 28 12:10:55 EDT 2006


Nick Maclaren wrote:

> |> a property looks like an attribute, not a method, so you're trying to call whatever
> |> your "joe()" method returns.
>
> Well, yes, that was pretty obvious - but what was NOT obvious is why it
> should do that for one of two identical methods.

identical?  you only applied @property to one of the methods, and then you're
surprised that only one of the methods were turned into a property?

> |> (that's what "a function for getting an attribute value" in the property documentation
> |> refers to).
>
> Well, as joe is an attribute of the class fred, and the decorator is applied
> to the declaration of joe within fred, I assumed that it referred to getting
> joe from fred.  That certainly doesn't appear to be the case

@property turns your "joe" method into a getter method for the (virtual) attribute
"joe".  when you access the attribute, the getter method will be called.  whatever
that method returns will be the attribute's value.  that's what the documentation
says, and that's what your code is doing.

</F> 






More information about the Python-list mailing list