<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
On 30-06-2010 20:56, Gary Herron wrote:
<blockquote cite="mid:4C2B9367.4080102@islandtraining.com"
type="cite">
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
<title></title>
On 06/30/2010 11:39 AM, Stef Mientki wrote:
<blockquote cite="mid:4C2B8F4D.6010005@gmail.com" type="cite">
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1">
<font size="+1">hello,<br>
<br>
I've lot of functions that returns their result in some kind
of tuple /
list / array,<br>
and if there is no result, these functions return None.<br>
Now I'm often what to do something if I've more than 1 element
in the
result.<br>
So I test:<br>
<br>
if len ( Result ) > 1 :<br>
<br>
But to prevent exceptions, i've to write ( I often forget)<br>
if Result and ( len ( Result ) > 1 ) :<br>
<br>
So I wonder why len is not allowed on None<br>
and if there are objections to extend the len function .<br>
<br>
thanks,<br>
Stef Mientki<br>
</font> </blockquote>
<br>
<br>
Because the natural interpretation of len only makes sense for
concepts
such as a container or collection. The value None is no such
thing.
Assigning a meaning to len(None) begs the question of meanings for
len(True), len(False), len(3.14), len(sys), ... This is a
slippery
slope, best avoided.<br>
<br>
But there are solutions:<br>
<br>
1. Have your functions return [] or () or whatever. If they are
to
return a list, and the list may be empty, [] is correct.<br>
<br>
</blockquote>
thanks guys,<br>
I think that will be the best idea.<br>
<br>
cheers,<br>
Stef<br>
<blockquote cite="mid:4C2B9367.4080102@islandtraining.com"
type="cite">
2. If you insist on a function returning a list sometimes and
other
values at other times (such as None), then be prepared to write
your
code which uses the result with test to determine which type was
returned. Fortunately that's not hard, as your one example
shows.<br>
<br>
3. Create a test function Empty(Result) which does what you want
returning a boolean and write your tests as:<br>
if Empty(Result): ...<br>
<br>
Gary Herron<br>
<br>
<br>
<br>
<br>
<br>
</blockquote>
<br>
</body>
</html>