Mateusz Loskot wrote:

> On 12 December 2014 at 12:26, Chris Angelico <ros...@gmail.com> wrote:
>> On Fri, Dec 12, 2014 at 10:21 PM, Mateusz Loskot <mate...@loskot.net>
>> wrote:
>>> I've got several cases which are not obvious to me.
>>> For instance, class Foo has a boolean attribute, read-write,
>>> which I see a couple of realisations for possible:
[...]
> I mentioned, setting the new value involves more changes to Foo()
> instance, so i's not possible to capture it with just an assignment.
> Hence, the discussion between property vs method.

If the calculation is cheap and fast and "feels like" getting/setting an
attribute, then use property.

If the calculation is expensive, or might fail, then use explicit
getter/setter methods.

I'm afraid that there is no objective way to tell when something "feels
like" an attribute. That depends partly on the class you are dealing with,
and partly on personal taste.



-- 
Steven

-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to