"no variable or argument declarations are necessary."

Ron Adam rrr at ronadam.com
Thu Oct 6 22:44:42 CEST 2005


Fredrik Lundh wrote:

> Ron Adam wrote:
> 
> 
>>Is there a way to conditionally decorate?  For example if __debug__ is
>>True, but not if it's False?  I think I've asked this question before. (?)
> 
> 
> the decorator is a callable, so you can simply do, say
> 
>     from somewhere import debugdecorator
> 
>     if not __debug__:
>         debugdecorator = lambda x: x

Ah... thanks.

I suppose after(if) lambda is removed it would need to be.

    def nulldecorator(f):
        return f

    if not __debug__:
       debugdecorator = nulldecorator


> or
> 
>     def debugdecorator(func):
>         if __debug__:
>             ...
>         else:
>             return func
> 
> etc.

This one came to mind right after I posted.  :-)


> </F> 







More information about the Python-list mailing list