[Tutor] 0 > "0" --> is there a "from __future__ import to make this raise a TypeError?
Oscar Benjamin
oscar.j.benjamin at gmail.com
Mon Oct 12 16:37:43 EDT 2015
On Mon, 12 Oct 2015 17:15 Albert-Jan Roskam <sjeik_appie at hotmail.com> wrote:
Hi,
In Python 2 one can do silly apple-pear comparisons such as 0> "0".*)
"CPython implementation detail: Objects of different types except numbers
are ordered by their type names; objects of the same types that don’t
support proper comparison are ordered by their address.". In Python3 this
has been fixed (it raises a TypeError). Is there a way to emulate this
behavior in Python 2?
Why do you want to? This kind of thing is nice to have when it's there by
default since it can help pick up errors. When it's not there that's
unfortunate which is why this was changed in Python 3 but it's not really
essential.
Most of the time you won't mix strings and ints unless it's a mistake. Are
you worried about making mistakes? Why not just test your code under Python
3 if so?
--
Oscar
More information about the Tutor
mailing list