Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > why are functions greater than numbers?

Reply
Thread Tools

why are functions greater than numbers?

 
 
Alan
Guest
Posts: n/a
 
      01-24-2011
Why do function objects compare in this way to numbers?
Thanks,
Alan Isaac


>>> def f(): return

....
>>> f>5

True

 
Reply With Quote
 
 
 
 
Ian Kelly
Guest
Posts: n/a
 
      01-24-2011
On Mon, Jan 24, 2011 at 2:51 PM, Alan <(E-Mail Removed)> wrote:
> Why do function objects compare in this way to numbers?
> Thanks,
> Alan Isaac
>
>
>>>> def f(): return

> ...
>>>> f>5

> True


http://docs.python.org/library/stdty...ml#comparisons

Python 3 fixes this particular wart.
 
Reply With Quote
 
 
 
 
Dan Stromberg
Guest
Posts: n/a
 
      01-24-2011
On Mon, Jan 24, 2011 at 1:51 PM, Alan <(E-Mail Removed)> wrote:
> Why do function objects compare in this way to numbers?
> Thanks,
> Alan Isaac
>
>
>>>> def f(): return

> ...
>>>> f>5

> True
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


They shouldn't, but did in 2.x, and no longer do in 3.x:

$ /usr/local/cpython-3.1/bin/python3
cmd started 2011 Mon Jan 24 02:39:50 PM
Python 3.1.2 (r312:79147, Aug 18 2010, 18:21:44)
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def f():

.... return 'abc'
....
>>> f > 5

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: function() > int()
>>>

 
Reply With Quote
 
MRAB
Guest
Posts: n/a
 
      01-24-2011
On 24/01/2011 21:51, Alan wrote:
> Why do function objects compare in this way to numbers?
> Thanks,
> Alan Isaac
>
>
>>>> def f(): return

> ...
>>>> f>5

> True
>

In Python 2 any object can be compared in this way to any other. The
result is arbitrary but consistent.

In Python 3 that has changed because in practice it's more trouble than
it's worth:

>>> def f(): return


>>> f>5

Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
f>5
TypeError: unorderable types: function() > int()

It's usually a good sign that there's a bug somewhere.
 
Reply With Quote
 
Terry Reedy
Guest
Posts: n/a
 
      01-24-2011
On 1/24/2011 4:51 PM, Alan wrote:
> Why do function objects compare in this way to numbers?
> Thanks,
> Alan Isaac
>
>
>>>> def f(): return

> ...
>>>> f>5

> True


In 3.x
>>> def f(): pass


>>> f > 5

Traceback (most recent call last):
File "<pyshell#39>", line 1, in <module>
f > 5
TypeError: unorderable types: function() > int()

There is a historical explanation in many past posts and probably in the
FAQ.

--
Terry Jan Reedy

 
Reply With Quote
 
Emile van Sebille
Guest
Posts: n/a
 
      01-24-2011
On 1/24/2011 1:51 PM Alan said...
> Why do function objects compare in this way to numbers?


To provide ordering capabilities. IIRC, comparisons of differing types
are arbitrary but consistent.


Emile

> Thanks,
> Alan Isaac
>
>
>>>> def f(): return

> ...
>>>> f>5

> True
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why are uploaded files to ASP.NET web Application greater than 12MBbeing shown as 0MB? newemployee909090@gmail.com ASP .Net 1 12-11-2012 08:30 AM
Include header files in quotes or less-than greater-than signs? Dwight Army of Champions C++ 4 03-17-2010 06:39 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
regex problem: 'greater than' 'less than' and 'equals' not matching! falcon Java 10 02-24-2006 01:23 PM
Enforcing that value entered is greater than a specified value BobRoyAce ASP .Net 7 03-03-2005 05:05 PM



Advertisments