On 12/29/2013 01:38 PM, Steven D'Aprano wrote:
>In the previous timer function that I was using, it defined a timer class,
>and then I had to instantiate it before I could use it, and then it saved a
>list of timing results. I think in yours, it adds attributes to each
>instance of a function/method, in which the relevant timings are stored.
Correct. Rather than dump those attributes on the original function, it
creates a new function and adds the attributes to that. The new function
wraps the older one, that is, it calls the older one:

def f(x):
     return g(x)

We say that "f wraps g". Now, obviously wrapping a function just to
return its result unchanged is pretty pointless, normally the wrapper
function will do something to the arguments, or the result, or both.

Or add metadata, as in your case the 'count'.
This pattern is often used in parsing to add metadata (semantic, or stateful, usually) to bare match results.

Denis
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to