Hwy doesn't len(None) return zero ?
Zubin Mithra
zubin.mithra at gmail.com
Wed Jun 30 14:54:31 EDT 2010
On Thu, Jul 1, 2010 at 12:09 AM, Stef Mientki <stef.mientki at gmail.com>wrote:
> hello,
>
> I've lot of functions that returns their result in some kind of tuple /
> list / array,
> and if there is no result, these functions return None.
> Now I'm often what to do something if I've more than 1 element in the
> result.
> So I test:
>
> if len ( Result ) > 1 :
>
> But to prevent exceptions, i've to write ( I often forget)
> if Result and ( len ( Result ) > 1 ) :
>
use
if Result:
<do something>
Checking the length would be a bad idea.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20100701/871c1bec/attachment-0001.html>
More information about the Python-list
mailing list