Checking the boolean value of a collection

Marco Bizzarri marco.bizzarri at gmail.com
Fri Sep 12 17:01:11 CEST 2008


On Fri, Sep 12, 2008 at 4:44 PM, Diez B. Roggisch <deets at nospam.web.de> wrote:
>>> if any(instance.forbitToClose(archivefolder) for instance in
>>> self.findActiveOutgoingRegistrationInstances())
>>
>> Can you clarify where I can find "any"? It seems to me I'm unable to find
>> it...
>
> It's part of python2.5.
>
> If you don't have that, you can write it your own and stuff it into
> __builtins__:
>
>>>> def any(iterable):
> ...     for item in iterable:
> ...         if item:
> ...              return True
> ...     return False
> ...
> ... __builtins__.any = any
>
>
> You might also want to add all, the companion of any:
>
>
>>>> def all(iterable):
> ...     for item in iterable:
> ...         if not item:
> ...              return False
> ...     return True
> ...
>
> Diez
> --
> http://mail.python.org/mailman/listinfo/python-list
>

Thanks for the clarification, Diez! Indeed, I tried python2.3 and
python2.4, and of course not python2.5 ;)

I would like to make  this available to the whole project. I suspect I
could put it in the package __init__.py... in that way, the
__builtins__ namespace should have it... am I right?

-- 
Marco Bizzarri
http://notenotturne.blogspot.com/
http://iliveinpisa.blogspot.com/



More information about the Python-list mailing list