def fast_int(x, key=lambda x: x, nan=None, uni=unicodedata.digit):
"""\
Convert a string to a int 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+-':
try:
return long(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)
评论列表
文章目录