def fast_float(x, key=lambda x: x, nan=None,
uni=unicodedata.numeric, nan_inf=nan_inf):
"""\
Convert a string to a float quickly, return input as-is if not possible.
We don't need to accept all input that the real fast_int accepts because
the input will be controlled by the splitting algorithm.
"""
if x[0] in '0123456789+-.' or x.lstrip()[:3] in nan_inf:
try:
x = float(x)
return nan if nan is not None and x != x else x
except ValueError:
try:
return uni(x, key(x)) if len(x) == 1 else key(x)
except TypeError: # pragma: no cover
return key(x)
else:
try:
return uni(x, key(x)) if len(x) == 1 else key(x)
except TypeError: # pragma: no cover
return key(x)
评论列表
文章目录