Why is None <= 0

Duncan Booth duncan.booth at invalid.invalid
Tue Apr 29 11:11:05 EDT 2008


blaine <frikker at gmail.com> wrote:

> On Apr 29, 5:32 am, Duncan Booth <duncan.bo... at invalid.invalid> wrote:
>> =?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?= <mar... at v.loewis.de>
>> wrote: 
>> > (FWIW, in 2.x, x>=4?, it's None < numbers < anything else;
>> > numbers are ordered by value, everything else is ordered
>> > by type name, then by address, unless comparison functions
>> > are implemented).
>>
>> Quite apart from Jon pointing out that this isn't true for all cases
>> when copmparing against None, the other half also isn't true:
>>
>> >>> class C: pass
>> >>> C() < 5
>>
>> True
>>
>> That happens at least in Python 2.5.2 on win32. Yet another reason to
>> avoid old-style classes.
> 
> Sorry - but what are new style classes?
> 
New style classes are anything type derived from object. e.g.

   class D(object): pass

or (since list is derived from object):

   class E(list): pass

Old style classes are those which either have old-style base classes or 
no base class at all (and no __metaclass__ either but don't worry about 
that for now) e.g. the class C above.

The problem with old style classes is that various things either work 
subtly differently or don't work at all, but you don't get much warning. 
So basically steer clear of them. An example of something which doesn't 
work with old style classes would be the @property decorator: you can 
get the property, but setting it simply overwrites the property with the 
new value.

See http://www.google.co.uk/search?q=python+%22new+style%22 for more 
information.



More information about the Python-list mailing list