From: wheres pythonmonks on
I did the google search... I must be blind as I don't see any hits...

None is negative in Python? (v2.6)

http://www.google.com/search?ie=UTF-8&q=%22none+is+negative%22+python

>>> if None < -9999999.99: print "hi"

hi
>>>

>>> if -9999999 > None: print "hi"

hi
>>>

Is there a way to have the comparison raise an exception?

W
From: Benjamin Kaplan on
On Tue, Aug 3, 2010 at 1:17 PM, wheres pythonmonks
<wherespythonmonks(a)gmail.com> wrote:
>
> I did the google search... I must be blind as I don't see any hits...
>
> None is negative in Python?  (v2.6)
>
> http://www.google.com/search?ie=UTF-8&q=%22none+is+negative%22+python
>
> >>> if None < -9999999.99: print "hi"
>
> hi
> >>>
>
> >>> if -9999999 > None: print "hi"
>
> hi
> >>>
>
> Is there a way to have the comparison raise an exception?
>
> W


Use Python 3. One of the (backwards-incompatible) changes was to have
comparisons of incompatible types raise exceptions. The behavior in
Python 2 (not just with None, but with other built-in types as well)
was to return an arbitrary but consistent result.
From: Mithrandir on
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 08/03/2010 01:17 PM, wheres pythonmonks wrote:
> I did the google search... I must be blind as I don't see any hits...
>
> None is negative in Python? (v2.6)
>
> http://www.google.com/search?ie=UTF-8&q=%22none+is+negative%22+python
>
>>>> if None < -9999999.99: print "hi"
>
> hi
>>>>
>
>>>> if -9999999 > None: print "hi"
>
> hi
>>>>
>
> Is there a way to have the comparison raise an exception?
>
> W

I believe it's also because None lacks any binary value at all, whereas
- -99999999.99 or 0 have a value in binary.

For example:

if None < 0: print "hi"

>>> hi

if None > 0: print "hi"

>>>

But in human terms, None == 0 and None > -9999999.99.

- --
People should read more.
https://secure.wikimedia.org/wikipedia/en/wiki/User:MithrandirAgain
"All that is gold does not glitter,
not all those who wander are lost;
the old that is strong does not wither,
deep roots are not reached by the frost.
- From the ashes a fire shall be woken,
a light from the shadows shall spring;
renewed shall be blade that was broken,
the crownless again shall be king."
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJMWHwBAAoJEKo37V1xH7gTgvYH/j1j0fgKI5mlzIp4urxhh6Ki
49LVsZjVsISyD+NzvgV5b8hk0S9Ad+gpqaf8fBQJS36Ye1KtupA7W7CTr54roaK0
ZBN3o4XxPdRjxXeHnBUNi3bqjGMzDdIIFZbE/qKalxTj0ZYgtlCgnMiYXLEeeY5z
L0dzfn/qoMr6PjAtdlB9yp5amHcUeRzDos3hp13flsAj9Vq/pHyJmlPazME/vE0f
381bMXP52ud71BGcm8gRWdDqhJOUdJ52NZeEk0fKcxHsRvscjt1nQmCRp4IMDtFl
ws++tXcl0pY7KSAATb5dzzkhr/BJnKGb1JHRlQMMB0EEdtNOzJaDh63qbvSzTJI=
=9jHw
-----END PGP SIGNATURE-----
From: Grant Edwards on
On 2010-08-03, wheres pythonmonks <wherespythonmonks(a)gmail.com> wrote:

> I did the google search... I must be blind as I don't see any hits...
>
> None is negative in Python? (v2.6)

Not really.

> http://www.google.com/search?ie=UTF-8&q=%22none+is+negative%22+python
>
>>>> if None < -9999999.99: print "hi"
>
> hi
>>>>
>
>>>> if -9999999 > None: print "hi"
>
> hi
>>>>
>
> Is there a way to have the comparison raise an exception?

Use Python 3.x. Or perhaps there's a "from future import xxxx" way to
do that as well... Is there a list of available "from future"
features somewhere? I can't seem to figure out how to get Python
itself to give me a list -- my copy of Python 2.6 insists there's not
module named future.

--
Grant Edwards grant.b.edwards Yow! I have a very good
at DENTAL PLAN. Thank you.
gmail.com
From: Ned Deily on
In article
<AANLkTim1WMz-UJxuK4nO6b85hiidyQHaNu6ACYCCDap+(a)mail.gmail.com>,
wheres pythonmonks <wherespythonmonks(a)gmail.com> wrote:
> I did the google search... I must be blind as I don't see any hits...
>
> None is negative in Python? (v2.6)
>
> http://www.google.com/search?ie=UTF-8&q=%22none+is+negative%22+python
>
> >>> if None < -9999999.99: print "hi"
>
> hi
> >>>
>
> >>> if -9999999 > None: print "hi"
>
> hi
> >>>
>
> Is there a way to have the comparison raise an exception?

This is a well-known wart in Python 2. The behavior has been changed in
Python 3.

$ python
Python 2.6.5 (r265:79063, Jul 15 2010, 01:53:46)
[GCC 4.2.1 (Apple Inc. build 5659)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> None < -9.9
True
>>>
$ python3
Python 3.1.2 (r312:79360M, Mar 24 2010, 01:33:18)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> None < -9.9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: NoneType() < float()
>>>

--
Ned Deily,
nad(a)acm.org