Hwy doesn't len(None) return zero ?

Stephen Hansen me+list/python at ixokai.io
Wed Jun 30 15:08:50 EDT 2010


On 6/30/10 12:02 PM, Tim Chase wrote:
> On 06/30/2010 01:50 PM, Stephen Hansen wrote:
>> On 6/30/10 11:39 AM, Stef Mientki wrote:
>>> if len ( Result )> 1 :
>>>
>>> But to prevent exceptions, i've to write ( I often forget)
>>> if Result and ( len ( Result )> 1 ) :
>>
>> Just do:
>>
>> if Result:
>>
>> You don't have to do a length check> 1; because if Result has a length
>> of 0, it'll be false too. So the above check will catch both None, and
>> empty sequences.
>
> Not to counter the rest of your comment below (which is right on), the
> OP asked about "> 1", not "> 0" for which "if Result" would work...one
> character vs. more than one character (your test would be 0 vs more-than-0)

Gah, oops. You're right. I misread, my bad.

In that case yes, he's right and needs "if Result and len(Result) > 1"

-- 

    ... Stephen Hansen
    ... Also: Ixokai
    ... Mail: me+list/python (AT) ixokai (DOT) io
    ... Blog: http://meh.ixokai.io/




More information about the Python-list mailing list