__getitem__, __getslice__ question for python 2.2

Erik Max Francis max at alcyone.com
Wed May 15 03:55:40 EDT 2002


Ken Seehof wrote:

> I don't see the problem.  If x is 'a', x != int(x) evaluates to false,
> consistent with 'a' not being an integer.

No, 'a' != int('a') does not evaluate to false.  It raises a ValueError.

> If the actual type is important and you don't consider 2.0 to be an
> integer, you can say:
> 
>   if type(x) != int: ...

Only behaves as expected in Python 2.2 and later.  The canonical test is
type(x) != types.IntType.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, US / 37 20 N 121 53 W / ICQ16063900 / &tSftDotIotE
/  \ Who'd ever think it / Such a squalid little ending
\__/ The American and Florence, _Chess_
    Church / http://www.alcyone.com/pyos/church/
 A lambda calculus explorer in Python.



More information about the Python-list mailing list