title: convert string to float without silent NaN/Inf conversion
body: <p>I'd like convert strings to floats using Python 2.6 and later, but <em>without</em> silently converting things like <code>'NaN'</code> and <code>'Inf'</code> to float objects.  I do want them to be silently ignored, as with any text that isn't valid as a float representation.</p>
  
  <p>Before 2.6, <code>float("NaN")</code> would raise a ValueError on Windows.  Now it returns a float for which math.isnan() returns True, which is not useful behaviour for my application.  (As was pointed out, this has always been a platform-dependent behaviour, but consider it an undesirable behaviour for my purposes, wherever it happens.)</p>
  
  <p>Here's what I've got at the moment:</p>
  
  <pre><code>import math
  def get_floats(source):
      for text in source.split():
          try:
              val = float(text)
              if math.isnan(val) or math.isinf(val):
                  raise ValueError
              yield val
          except ValueError:
              pass
  </code></pre>
  
  <p>This is a generator, which I can supply with strings containing whitespace-separated sequences representing real numbers.  I'd like it to yield only those fields which are purely numeric representations of floats, as in "1.23" or "-34e6", but not for example "NaN" or "-Inf".  Things that aren't floats at all, e.g. "hello", should be ignored as well.</p>
  
  <p>Test case:</p>
  
  <pre><code>assert list(get_floats('1.23 foo -34e6 NaN -Inf')) == [1.23, -34000000.0]
  </code></pre>
  
  <p>Please suggest alternatives you consider more elegant, even if they involve "look before you leap" (which is normally considered a lesser approach in Python).</p>
  
  <p><strong>Edited</strong> to clarify that non-float text such as "hello" should just be ignored quietly as well.  The purpose is to pull out only those things that are real numbers and ignore everything else.</p>