comparing strings and ints

Randall Hopper aa8vb at yahoo.com
Wed Apr 12 07:58:12 EDT 2000


Gordon McMillan:
 |Randall Hopper wrote:
 |> Fredrik Lundh:
 |>  |
 |>  |    Objects of different types always compare unequal, and are
 |>  |    ordered consistently but arbitrarily.
 |> 
 |> I can see 45 == '45' being false, and 45 != '45' being true.  But it seems
 |> to me that not throwing an exception for attempts at an ordered comparison
 |> with logical ordering operators (<, <=, etc.) on objects of different
 |> primitive types (e.g. 45 < '45', 45 > '45') only lets bugs pass through.
 |> 
 |> Is there a case where this could be useful (with its undefined behavior)?
 |> I believe that is the root of the question.
 |
 |I'd happily bet your wife and firstborn child that there's code that
 |relies on it <wink>, if only because after sorting a list, all the ints
 |will end up in a clump, and all the strings in another, etc. 


Oh, I also have __no doubt__ that someone is using this unofficial,
undocumented behavior.  But they don't have a leg to stand on if the
ordering breaks in a future Python version ;-)


Capitalize-on-Python's-undefined-behavior-while-you-can'-ly yours,

Randall

-- 
Randall Hopper
aa8vb at yahoo.com




More information about the Python-list mailing list