473,403 Members | 2,270 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Why is None <= 0

Hi,
>>None <= 0
True

Why?
Is there a logical reason?

Gregor
Jun 27 '08 #1
17 10199
On Fri, 25 Apr 2008 20:27:15 +0200
Gregor Horvath <gh@gregor-horvath.comwrote:
>>None <= 0
True

Why?
Why not?
Is there a logical reason?
Everything in Python can compare to everything else. It is up to the
programmer to make sure that they are comparing reasonable things.

--
D'Arcy J.M. Cain <da***@druid.net | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
Jun 27 '08 #2
Gregor Horvath wrote:
>>None <= 0
True
More accurately:
>>None < 0
True
Why?
Is there a logical reason?
None is "less than" everything except for itself:
>>None < 'a'
True
>>None < False
True
>>None == None
True

In my humble opinion, I think that comparisons involving None should
return None, but I trust that the designers came up with this for very
good reasons. As far as I know I've never been bitten by it.

Paul
Jun 27 '08 #3
D'Arcy J.M. Cain schrieb:
On Fri, 25 Apr 2008 20:27:15 +0200
Gregor Horvath <gh@gregor-horvath.comwrote:
> >>None <= 0
True

Why?

Why not?
Because, from http://www.python.org/dev/peps/pep-0020/ :

Errors should never pass silently.
In the face of ambiguity, refuse the temptation to guess.

Greg
Jun 27 '08 #4
On 2008-04-25, Gregor Horvath <gh@gregor-horvath.comwrote:
Hi,
>None <= 0
True

Why?
Comparing objects of differing types produces an undefined
result. Next time you do it, it might return False. (Well,
it's not really going to, but it's allowed to.)
Is there a logical reason?
For what? There's no reason it returns true rather than false.
The more interesting question is why doesn't it raise an
exception. <ducks>

--
Grant Edwards grante Yow! These PRESERVES should
at be FORCE-FED to PENTAGON
visi.com OFFICIALS!!
Jun 27 '08 #5
On Fri, 25 Apr 2008 11:54:23 -0700
Paul McNett <p@ulmcnett.comwrote:
In my humble opinion, I think that comparisons involving None should
return None...
Like relational databases.

--
D'Arcy J.M. Cain <da***@druid.net | Democracy is three wolves
http://www.druid.net/darcy/ | and a sheep voting on
+1 416 425 1212 (DoD#0082) (eNTP) | what's for dinner.
Jun 27 '08 #6
Gregor Horvath wrote:
Hi,
>None <= 0
True

Why?
Is there a logical reason?

Gregor
--
http://mail.python.org/mailman/listinfo/python-list
In early Python, the decision was made that the comparison of *any* two
objects was legal and would return a consistent result. So objects of
different types will compare according to an ordering on their types (an
implementation dependent, unspecified, but consistent ordering), and
objects of the same type will be compared according to rules that make
sense for that type.

Other implementations have the right to compare an integer and None
differently, but on a specific implementation, the result will not change.

Python 3 will raise an exception on such comparisons.

Gary Herron

Jun 27 '08 #7
In my humble opinion, I think that comparisons involving None should
return None, but I trust that the designers came up with this for very
good reasons. As far as I know I've never been bitten by it.
It's fixed in Python 3.x. Python 3.x refuses to compare objects unless
one of both objects has explicit support for both types:
>>1 < None
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: int() < NoneType()

Jun 27 '08 #8
In my humble opinion, I think that comparisons involving None should
return None, but I trust that the designers came up with this for very
good reasons. As far as I know I've never been bitten by it.
It's fixed in Python 3.x. Python 3.x refuses to compare objects unless
one of both objects has explicit support for both types:
>>1 < None
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: int() < NoneType()

Jun 27 '08 #9
On 2008-04-25, Martin v. Löwis <ma****@v.loewis.dewrote:
None is smaller than anything.
According to Tim Peters, this is not true.

See http://bugs.python.org/issue1673405
Jun 27 '08 #10
On 2008-04-25, D'Arcy J.M. Cain <da***@druid.netwrote:
On Fri, 25 Apr 2008 20:27:15 +0200
Gregor Horvath <gh@gregor-horvath.comwrote:
> >>None <= 0
True

Why?

Why not?
>Is there a logical reason?

Everything in Python can compare to everything else.
Not true.

Python 2.4.4 (#1, Mar 20 2008, 09:20:52) [GCC 3.4.6 (Gentoo 3.4.6-r2, ssp-3.4.6-1.0, pie-8.7.10)] on linux2
>>3j < 7
Traceback (most recent call last):
File "<stdin>", line 1, in ?
TypeError: no ordering relation is defined for complex numbers
It is up to the programmer to make sure that they are
comparing reasonable things.
True.

--
Grant Edwards grante Yow! BEEP-BEEP!! I'm a
at '49 STUDEBAKER!!
visi.com
Jun 27 '08 #11
Grant Edwards <gr****@visi.comwrites:
On 2008-04-25, D'Arcy J.M. Cain <da***@druid.netwrote:
On Fri, 25 Apr 2008 20:27:15 +0200
Gregor Horvath <gh@gregor-horvath.comwrote:
>>None <= 0
True
Everything in Python can compare to everything else.

Not true.
Even more untrue in Python 3.0:

Comparisons other than == and != between disparate types will
raise an exception unless explicitly supported by the type

<URL:http://www.python.org/dev/peps/pep-3100/#core-language>
<URL:http://mail.python.org/pipermail/python-dev/2004-June/045111.html>

--
\ "We demand rigidly defined areas of doubt and uncertainty!" -- |
`\ Vroomfondel, _The Hitch-Hiker's Guide To The Galaxy_, Douglas |
_o__) Adams |
Ben Finney
Jun 27 '08 #12
Gregor Horvath wrote:
D'Arcy J.M. Cain schrieb:
>On Fri, 25 Apr 2008 20:27:15 +0200
Gregor Horvath <gh@gregor-horvath.comwrote:
>> >>None <= 0
True

Why?

Why not?

Because, from http://www.python.org/dev/peps/pep-0020/ :

Errors should never pass silently.
In the face of ambiguity, refuse the temptation to guess.

Greg
Good point.

The problem is the typical one; Python did not originally
have a Boolean type, and the retrofit resulted in weird semantics.
C has the same issue.

John Nagle
Jun 27 '08 #13
=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?= <ma****@v.loewis.dewrote:
(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.

Jun 27 '08 #14
On Apr 29, 5:32 am, Duncan Booth <duncan.bo...@invalid.invalidwrote:
=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?= <mar...@v.loewis.dewrote:
(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?
Jun 27 '08 #15
blaine <fr*****@gmail.comwrote:
On Apr 29, 5:32 am, Duncan Booth <duncan.bo...@invalid.invalidwrote:
>=?ISO-8859-15?Q?=22Martin_v=2E_L=F6wis=22?= <mar...@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.
Jun 27 '08 #16
On Apr 25, 8:17 pm, Jon Ribbens <jon+use...@unequivocal.co.ukwrote:
On 2008-04-25, Martin v. Löwis <mar...@v.loewis.dewrote:
None is smaller than anything.

According to Tim Peters, this is not true.

See http://bugs.python.org/issue1673405
This is unfortunate. I would advocate
something like ordering "incomparable objects"
by the name of their type or something
similar.

When building indexing structures it can be
very nice to be able to construct a list of
heterogeneous tuples and sort them without getting
an exception. Implementing this using L.sort(cmp) where
cmp is implemented in Python can result in
a significant speed penalty.

What's up with Tim Peters anyway? I haven't
seen much from him for a while.
-- Aaron Watters

===
http://www.xfeedme.com/nucular/pydis...ote+tim+peters
Jun 27 '08 #17

"Aaron Watters" <aa***********@gmail.comwrote in message
news:76**********************************@24g2000h sh.googlegroups.com...
|What's up with Tim Peters anyway? I haven't seen much from him for a
while.

I miss him too ;-)
He occasionally responds to tracker or pydev math issues where his unique
knowledge and experience is really needed. (As recently as last Jan).
That is all I know.
tjr

Jun 27 '08 #18

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
13
by: Dan R Brown | last post by:
I have a large form that is generated dynamically in a jsp using xml / xslt. So, to break up this form into several "tabbed" sections, I break up the form using <div> tags. Each <div...
3
by: Iain Hallam | last post by:
Hi. I've been using display:none on the style property of some <option> elements in my forms, which works fine with Mozilla - as expected it removes the option from my dropdown (although it...
11
by: Les Paul | last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's just like a Wiki page, but my own very simple version. It's a page full of plain old HTML content, and then at the bottom,...
5
by: z. f. | last post by:
sorry about the previous post, by mistake not completed. i have an asp.net page with the line <%@ OutputCache Duration="30" VaryByParam="none" %> but when i make requests to the page with...
2
by: YeeCN | last post by:
Hi, I have a page which contain a image control for displaying a .gif file. The application allows the user to upload a different image to replace the existing one - but when I do...
2
by: GloStix | last post by:
For some reason, FF likes to put a black underline on all my buttons. No matter what I do, it has the line I've tried displaying as block and cursor, anything.. Also I've been trying to get it so...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.