Or use the zope function same_type: if same_type(1,somevar): print '"it's an int' Terry Hancock wrote:
On Tuesday 15 June 2004 01:00 pm, Asad Habib wrote:
Hello. Does anyone know of a python function that returns a value based on whether or not its argument is an integer? Any help would be greatly appreciated. Thanks.
Well, the usual way to check in Python is an idiom like:
if type(spam)==type(1): print "Yep, it's an integer." else: print "Whoops. Not an integer."
so it's not a function, but an expression.
Unfortunately, Zope doesn't allow you to use "type()" in a Python script for mysterious security reasons. So, it's either go to an external method, allow that import, or find out an alternate way to do it.
*Converting* to an integer is done with int(), though. And you could always ask:
if int(spam)==spam: print "Yep, it's an integer."
Technically this would accept "1.0000" as well as "1", but it's unclear to me why you would care about the actual storage format versus the meaning. It won't accept '1', though, which might matter if spam comes from a web form.
Cheers, Terry
-- Terry Hancock ( hancock at anansispaceworks.com ) Anansi Spaceworks http://www.anansispaceworks.com
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )