Hwy doesn't len(None) return zero ?
Tim Chase
sed at thechases.com
Wed Jun 30 15:02:13 EDT 2010
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)
>> So I wonder why len is not allowed on None
>> and if there are objections to extend the len function .
>
> Len is not allowed on None, becaues None is not a sequence, and doesn't
> have a length. None, *very* much on purpose, is distinct and does not
> behave like anything else. It's the "I'm not anything" object.
-tkc
More information about the Python-list
mailing list