check if object is number

Steven Bethard steven.bethard at gmail.com
Fri Feb 11 14:48:36 EST 2005


Dan Bishop wrote:
> Steven Bethard wrote:
> 
>>Is there a good way to determine if an object is a numeric type?
> 
> How about this?
> 
> ... def is_number(x):
> ...    try:
> ...       x + 1
> ...       return True
> ...    except TypeError:
> ...       return False

Great, thanks!  That's the kind of thing I was looking for!

Steve



More information about the Python-list mailing list