Simple Function Decorator Sample Snippet

Mark H Harris harrismh777 at gmail.com
Tue May 13 02:04:39 EDT 2014


On 5/13/14 12:54 AM, Steven D'Aprano wrote:
> I don't think that this idea is original to you :-) I'm pretty sure many
> people have come up with the idea of a decorator that just announces when
> it runs and when it is called. I know I have  :-)

    oh, absolutely... every piece of that thing comes from somebody 
(about six somebodies to be exact) what makes it unique is that its 
compressed, in the right order (I think), and 'without' extraneous 
gibberish that confuses the whole dang thing.

>
> People keep independently inventing this because it's an obvious, and
> easy to understand, example. Nicely done.

    Its obvious until you get to the @charater.  In fact its taken so 
obviously by *everyone* that no one actually gets it explained without 
eight pages or twelve steps of something until its all confused.


> I tried to run your code, but every line is quoted with a > which causes
> a syntax error. Was there a reason you quoted the snippet?

Yes, because depending on your interface the code can get mangled (the 
indentation thing breaks).  the quoted paste seems to avoid this mostly 
with the downside that the quote characters need to be striped from the 
py file.   <sorry>   by the way, any suggestions are welcome regarding 
that too...  there doesn't really seem to be a good way to share code on 
the group consistently.

marcus




More information about the Python-list mailing list