isFloat: Without Exception-Handling

Chad Netzer cnetzer at mail.arc.nasa.gov
Fri Oct 4 21:05:19 EDT 2002


On Friday 04 October 2002 17:59, I wrote:

> This works better, but does extra work:

Duh, Chad!  Just change "and" to "or":

def isFloat(s):
    try: return float(s) or True
    except (ValueError, TypeError), e: return False

-- 

Chad Netzer
cnetzer at mail.arc.nasa.gov




More information about the Python-list mailing list