check if object is number

Michael Hartl mhartl at post.harvard.edu
Fri Feb 11 17:59:51 EST 2005


Oops, my bad.  The utilities file I use gets loaded automatically when
I start my interpreter, so I mistook isnumber for a built-in function.
A battle-tested isnumber function is defined in Peter Norvig's utils.py
(http://aima.cs.berkeley.edu/python/utils.py):

#def isnumber(x):
#    "Is x a number? We say it is if it has an __int__ method."
#    return hasattr(x, '__int__')

Michael

--
Michael D. Hartl, Ph.D.
Chief Technology Officer
http://quarksports.com/




More information about the Python-list mailing list