__getitem__, __getslice__ question for python 2.2
Fredrik Juhlin
laz at strakt.com
Wed May 15 03:30:29 EDT 2002
On Wed, 2002-05-15 at 09:16, Ken Seehof wrote:
> Eric Max Francis wrote:
> > Raymond Hettinger wrote:
> >
> > > "logistix" <logstx at bellatlantic.net> wrote
> > >
> > > > Also, some people don't like to use isinstance, but I'm not sure how
> > > > else to
> > > > tell if you got an int.
> > >
> > > if x != int(x): print 'expected an integer'
> >
> > This is a pretty poor test. Consider the cases where x is 'a', or when
> > it is 2.0.
>
> I don't see the problem. If x is 'a', x != int(x) evaluates to false,
> consistent with 'a' not being an integer.
This doesn't work for me, at any rate:
Python 2.2.1 (#1, Apr 21 2002, 08:38:44)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x = 'a'
>>> if x != int(x): print "Expected an integer"
...
Traceback (most recent call last):
File "<stdin>", line 1, in ?
ValueError: invalid literal for int(): a
//FJ
More information about the Python-list
mailing list