Descriptors vs Property

Chris Angelico rosuav at gmail.com
Sat Mar 12 01:05:47 EST 2016


On Sat, Mar 12, 2016 at 4:59 PM, Veek. M <vek.m1234 at gmail.com> wrote:
> A property uses the @property decorator and has @foo.setter
> @foo.deleter.
>
> A descriptor follows the descriptor protocol and implements the __get__
> __set__ __delete__ methods.
>
> But they both do essentially the same thing, allow us to do:
> foo = 10
> del foo
> x = foo
>
> So why do we have two ways of doing this?

The descriptor protocol is what powers the @property decorator. It's
like asking why we have both lists and sequences; the sequence
protocol is how you interact with lists.

ChrisA



More information about the Python-list mailing list