newb question about @property

Marko Rauhamaa marko at pacujo.net
Mon Oct 2 02:34:42 EDT 2017


Chris Angelico <rosuav at gmail.com>:

> Yes, that's correct. The *descriptor* protocol is what allows
> "foo.bar" to cause a function to be executed

That mechanism allows you to expose data fields in the API. If the
implementation later changes, you can emulate the data fields.

I must say, though, I have yet to run into a need for descriptors.

> the *decorator* protocol is what lets you "tag" a function:

i have yet to need that, either. I have *seen* a semi-useful decorator
in code once (@contextlib.contextmanager) but still would prefer
explicit dunder methods.


Marko



More information about the Python-list mailing list