A question about string and float number

Tyler Breisacher dancinguy at linkline.com
Thu Aug 7 07:37:05 CEST 2008

It's generally a bad idea to use "except" without naming a specific 
exception. The exception you might expect in this case is ValueError. 
Any other exception *should* be uncaught if it happens. By the way, this 
method will return true for integers as well as floats. For example, 
isFloat('3') will return 3.0. So make sure this is what you want, since 
it wasn't 100% clear from the original message.

Wei Guo wrote:
> #this is a better way of testing a string for float
> def isFloat(s):
>     try:
>         s = float(s)
>     except:
>         return False
>     return True

More information about the Python-list mailing list