Lost in descriptor land

Ian Kelly ian.g.kelly at gmail.com
Sat Jul 2 19:06:47 EDT 2016


On Sat, Jul 2, 2016 at 5:32 AM, Ankush Thakur <ankush.thakur53 at gmail.com> wrote:
> On Friday, July 1, 2016 at 9:13:19 AM UTC+5:30, Lawrence D’Oliveiro wrote:
>>
>> > Shouldn't we be instead using self.celcius in, say, __init__() and then
>> > everything will work fine?
>>
>> I guess it might. But this way, using descriptors, all the setup is done once at class definition, rather then every time in class instantiation.
>
> So you're saying the (sole) reason to instantiate descriptor classes at class-level is performance?

Performance might be part of it (it also saves some checks when
looking up attributes), but in my opinion a big reason for it is
separation of responsibilities. Classes define object behavior;
instances contain object state. For example, you can't define a method
on an instance (though you can certainly store a function there and
call it).



More information about the Python-list mailing list