newb question about @property
Stephan Houben
stephanh42 at gmail.com.invalid
Sun Oct 1 15:36:14 EDT 2017
Op 2017-10-01, Bill schreef <BILL_NOSPAM at whoknows.net>:
> I watched an example on YouTube where someone wrote a simple descriptor
> ("@Time_it) to output the amount of time that it took ordinary functions
> to complete. To be honest, I AM interested in descriptors.
Are you sure you are not confusing deSCRIPTtors and deCORAtors here?
@Time_it
is decorator syntax.
Despite the similarity in the words, there are totally different things.
Descriptors are objects with __get__, and optionally __set__ and
__delete__ methods (i.e. they implement the descriptor protocols).
Decorators aren't really an official type, but loosely speaking these
are any functions which can be applied meaningfully with a single
function or class as argument. Some very mundane functions can be
(ab)used as decorators.
In [1]: @repr
...: def hello():
...: pass
...:
In [2]: hello
Out[2]: '<function hello at 0x1048a50d0>'
Stephan
More information about the Python-list
mailing list