[Zope] Python Function to Test for Integer Type

Terry Hancock hancock at anansispaceworks.com
Wed Jun 16 02:51:57 EDT 2004


On Wednesday 16 June 2004 01:10 am, Paul Winkler wrote:
> Python 2.3.3 (#1, Feb  2 2004, 03:53:32) 
> [GCC 3.2.3 20030422 (Gentoo Linux 1.4 3.2.3-r3, propolice)] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
> >>> int(1) == int(1.0) == int('1')
> True

That's not what I wrote -- and it would always be true.

*This* doesn't work:

Python 2.3.4 (#2, May 29 2004, 03:31:27)
[GCC 3.3.3 (Debian 20040417)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> int(1)=='1'
False
>>>

which is equivalent to the test I had above.

But this does:
>>> int(1)==1.0
True

Strings equate differently from numbers.

The test will fail though if the floating point
value isn't *exactly* an integer.

>>> int(1)==1.000001
False

Cheers,
Terry

--
Terry Hancock ( hancock at anansispaceworks.com )
Anansi Spaceworks  http://www.anansispaceworks.com




More information about the Zope mailing list