isFloat: Without Exception-Handling
Rajarshi Guha
rajarshi at presidency.com
Wed Sep 18 11:40:51 EDT 2002
On Wed, 18 Sep 2002 11:41:47 -0400, Thomas Guettler wrote:
> 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
def isFloat(string):
if type(string) == type(1.0):
return 1
else
return 0
This should do what you want without exceptions
More information about the Python-list
mailing list