Python 3.0 - is this true?

Arnaud Delobelle arnodel at googlemail.com
Mon Nov 10 14:26:46 EST 2008


Robin Becker <robin at reportlab.com> writes:

> Steve Holden wrote:
> .........intain).
>>
>> Of course, using SQL against a traditional RDBMS will not return rows
>> with NULL values for salary in a query such as
>>
>>   SELECT name, address WHERE salary < 10000
>>
>> precisely *because* NULL (absence of value) does not compare with any
>> value. So you could say that 3.0 is forcing us to acknowledge database
>> reality ;-)
>>
>> regards
>>  Steve
> on the other hand I find it odd that
>
> cmp(None,None) fails in Python 3 when None==None returns True.
>
> In fact it seems that because None is non-comparable I need to write
> at least three of the comparisons at least as two only leads to
> errors. So now even though I can sort my objects with None I still
> cannot sort [None,None]

Using the key argument you don't have to do all this:

Python 3.0rc1+ (py3k:66521, Sep 21 2008, 07:58:29) 
[GCC 4.0.1 (Apple Inc. build 5465)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def none_first(x):
...     return (0,) if x is None else (1, x)
... 
>>> sorted([5, 4, None, 8, None], key=none_first)
[None, None, 4, 5, 8]

-- 
Arnaud



More information about the Python-list mailing list