convert string to float without silent NaN/Inf conversion
- by Peter Hansen
I'd like convert strings to floats using Python 2.6 and later, but without silently converting things like 'NaN' and 'Inf'.
Before 2.6, float("NaN") would raise a ValueError. Now it returns a float for which math.isnan() returns True, which is not useful behaviour for my application.
Here's what I've got at the moment:
import math
def…