[Baypiggies] FW: Baypiggies Digest, Vol 41, Issue 3

Smith1, Robert E robert.e.smith1 at lmco.com
Thu Mar 5 10:00:34 CET 2009

>>On Fri, Feb 27, 2009 at 5:57 PM, Glen Jarvis <glen at glenjarvis.com>
>> JJ,
>> ?? ?Last night you mentioned you had a real easy code snippet
(TimeIt) that
>> clearly explains decorators (or what we sometimes refer to as
>> decorators). Do you mind sending a copy of that code snippet to
>> the Newbie Nugget last night? I'm learning about?decorators?and am
>> to get my head around them, so any extra code would be helpful.
>> Warmest Regards,

>No problem.  Tell me if it makes sense :)


I put some print statements into your code to try and understand it. It
appears that the logged "decorator function" gets executed during
import/load, which also causes either pre_logged(f) or post_logged(f) to
executed. This statement appears to be the one that invokes
pre_logged(f) or post_logged(f) (or at least it occurs right before):

return {"pre": pre_logged, "post": post_logged}[when]

Is that correct - that invokes one of those two functions? And if so,
how does "return pre_logged" invoke "pre_logged(f)"? 

Also, why is "f" explicitly declared as a parameter for "log",
"pre_logged", and "post_logged", but not "logged"?


More information about the Baypiggies mailing list