[Tutor] Generator next()

Keith Winston keithwins at gmail.com
Sun Dec 29 07:57:31 CET 2013


On Sat, Dec 28, 2013 at 4:45 AM, Steven D'Aprano <steve at pearwood.info>wrote:

> That's my idea of an instrumented function :-)
>
> Feel free to ask for a explanation of how it works.
>


Hey Steve or anyone: That seems like a very clean timer function, and while
I have it working I only understand it caricaturistically... Sooo...

I don't really get the inner thing, I tried to look it up, but I don't
think I found the right thing, just references to nested functions. I'd
like to understand what I'm looking at better, but can't figure out what
question to ask...

Also: in the timer function, it has a series of attribute assignments to
0/None after the inner function definition... from the behaviour, I assume
those are applied once, the first time the timer function is called
wrapping a new method/function, and then not again, but that doesn't really
make sense. Again, I don't really have a well-formed question, maybe that's
clear enough?

The functools module seems really interesting.

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. I
guess that's just an observation, I've played with it a bit and it's
interesting. You said you didn't like the prior implementation, I'd be
interested in anything further you have to say about why: specifically, you
called it a coroutine, and a "decorator factory" (tell me you made that
up). Any more on that? Sorry to be so vague, I will be continuing my
efforts to understand it all even if you (and everyone) are too busy to
reply. Thanks for all the help as always.

-- 
Keith
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20131229/5fd50b0f/attachment.html>


More information about the Tutor mailing list