isFloat: Without Exception-Handling

Thomas Guettler zopestoller at thomas-guettler.de
Wed Sep 18 11:41:47 EDT 2002


Hi!

Is there a way to write the following
method without using exceptions?

def isFloat(string):
     is_float=1
     try:
         float(string)
     except:
         is_float=0
     return is_float

print isFloat("asdf") # --> 0
print isFloat("0.1")  # --> 1

Somehow I don't like to catch exceptions. Maybe
that's because my first language was C.

  thomas




More information about the Python-list mailing list