Decorators, Identity functions and execution...

Chance Ginger cginboston at hotmail.com
Sun Apr 9 12:21:41 EDT 2006


First, thanks for the tip of 'tabs'. I keep forgetting
Outlook has some interesting rules about displaying text.

Thanks for the comment about happening at load time. That
resolved the problem (in my thinking)! I don't believe I
have an issue at all...

Peace,
CG.

On Sun, 09 Apr 2006 08:52:18 -0700, Carl Banks wrote:

> 
> Chance Ginger wrote:
>> On Sun, 09 Apr 2006 09:51:18 +0200, Fredrik Lundh wrote:
>>
>> > Chance Ginger" wrote:
>> >
>> >> If I define a decorator like:
>> >>
>> >> def t(x) :
>> >> def I(x) : return x
>> >> return I
>> >
>> > ... you get a syntax error.
>> >
>>
>> It isn't a syntax error...I tried it before I posted. In fact
>> def t(x) :
>> 	def I(x) : return x
>> 	return I
>>
>> is correct.
> 
> You've made the unfortunate mistake of indenting it with tabs, which do
> not show up on some newsreaders.  I see the tabs in Google; people
> using Microsoft Outlook do not.
> 
> Always use spaces when posting, and use them in your code as well.
> Spaces are the current recommended practice, and in the future tabs
> might become illegal.  I'd prefer tabs myself, but it's more important
> to respect community standards than to stick to some silly preference
> you have.
> 
> 
>> Decorators are a way to add "syntactic" sugar to Python,
>> extending it in ways that make it useful for tools. What
>> I am trying to do is lessen the impact on the time used
>> in executing Python code when I use some forms of decorators.
> 
> One suggestion.  Have you run the script, determined it's too slow, and
> are trying to optimize?  If not (and it doesn't sound like you are), I
> suggest that it's too soon to worry about whether this decorator has
> any overhead.  You may end up doing a lot of work optimizing that will
> ultimately have very little benefit.
> 
> Having said that, this decorator will not affect calling overhead at
> all.  The decorator is applied when the module is loaded, not when the
> decorated function is called.
> 
> 
> Carl Banks




More information about the Python-list mailing list