isFloat: Without Exception-Handling
Chad Netzer
cnetzer at mail.arc.nasa.gov
Fri Oct 4 23:19:44 EDT 2002
On Friday 04 October 2002 19:31, Jeff Epler wrote:
> On Fri, Oct 04, 2002 at 06:05:19PM -0700, Chad Netzer wrote:
> > def isFloat(s):
> > try: return float(s) or True
> > except (ValueError, TypeError), e: return False
>
> You mean
> def isFloat(s):
> try: return (float(s), True)[1]
> except (ValueError, TypeError), e: return False
Is there any instance when these will be different? I assume float() will
always return type< float >, and so not overload the 'and'. In which case,
my version doesn't have to construct a tuple (so possibly it's faster).
Just curious; for the specific case and'ing with a float, I can't think where
mine might go wrong (not off the top of my head, anyway).
--
Chad Netzer
cnetzer at mail.arc.nasa.gov
More information about the Python-list
mailing list