Decorators, Identity functions and execution...

Jorge Godoy godoy at ieee.org
Sun Apr 9 10:42:34 EDT 2006


Chance Ginger <cginboston at hotmail.com> writes:

> 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.

Indeed.  This is correct.  Fredrick's comment was related to the lack of
indentation in your code.

>
>>> and use it like:
>>>
>>> @t(X)
>>> def foo(a) :
>>> # definition of foo...
>>> pass
>> 
>> that's also a syntax error.
>
> Once again this isn't an error assuming you pass in a valid 'X'.

If your indentation is broken as above it doesn't matter what 'X' is. 

-- 
Jorge Godoy      <godoy at ieee.org>

"Quidquid latine dictum sit, altum sonatur."
- Qualquer coisa dita em latim soa profundo.
- Anything said in Latin sounds smart.



More information about the Python-list mailing list