[Zope] Counting the elements of a result in a ZCatalog
Tino Wildenhain
tino at wildenhain.de
Thu Jun 5 09:35:41 EDT 2008
Hi,
Marco Bizzarri wrote:
...
>> if result:
>> result_len = results.actual_result_count
>> else:
>> result_len = 0
>>
>> return result_len
>>
...
>
> Thanks for your answer, but there is something I do not understand:
>
> if results:
>
> an empty result from ZCatlog is false in a boolen condition?
Yes, thats standard Python behavior, empty lists, dictionaries
and similar objects are assumed "False" when used as boolean.
This means you could even write it this way:
return (results and results.actual_result_count) or 0
in python2.5 (not yet supported by Zope) even:
return results.actual_result_count if results else 0
Cheers
Tino
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3241 bytes
Desc: S/MIME Cryptographic Signature
Url : http://mail.zope.org/pipermail/zope/attachments/20080605/20ede395/smime.bin
More information about the Zope
mailing list