quiet conversion functions

Sion Arrowsmith siona at chiark.greenend.org.uk
Thu Apr 13 09:47:19 EDT 2006


Tim Chase  <python.list at tim.thechases.com> wrote:
>def CFloat(value):
>	try:
>		value = float(value)
>	except (ValueError, TypeError):
>		value = 0
>	return value

>>> type(CFloat(None))
<type 'int'>

I think you want value = 0.0 . And you might also want to consider
what errors you may be masking in silently turning *anything* into
a valid number.

-- 
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |    -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump



More information about the Python-list mailing list