我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用unicodedata.numeric()。
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)
def calibrate(self): data = (u'a', u'1', u' ', u'\u1234', u'\uFFFF') len_data = len(data) digit = unicodedata.digit numeric = unicodedata.numeric decimal = unicodedata.decimal category = unicodedata.category bidirectional = unicodedata.bidirectional decomposition = unicodedata.decomposition mirrored = unicodedata.mirrored combining = unicodedata.combining for i in xrange(self.rounds): c = data[i % len_data]
def is_number(s): """Determines if the input is numeric Args: s: The value to check. Returns: bool: ``True`` if the input is numeric, ``False`` otherwise. """ try: float(s) return True except ValueError: pass try: import unicodedata unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False #----------------------------------------------------------------------
def is_number(s): """ Check string for being a numeric value. http://pythoncentral.io/how-to-check-if-a-string-is-a-number-in-python-including-unicode/ """ try: float(s) return True except ValueError: pass try: import unicodedata unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
def fast_float(x, regex_matcher=float_re.match, uni=unicodedata.numeric): """Convert a string to a float quickly""" if type(x) in (int, long, float): return float(x) elif regex_matcher(x): return float(x.strip()) elif type(x) == unicode and len(x) == 1 and uni(x, None) is not None: return uni(x) else: return x
def is_number(s): try: float(s) return True except ValueError: pass try: import unicodedata unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
def is_number(s): try: float(s) return True except ValueError: pass try: unicodedata.numeric(s) return True except (TypeError, ValueError): pass return False
def convert_floats(data, integers=None): """ Convert all numeric values in dictionary to float type. """ integers = integers or [] for key, value in data.iteritems(): try: if is_number(value): if key in integers: data[key] = int(value) else: data[key] = float(value) except: pass return data
def is_number(s): s = s.replace(',','') try: float(s) return True except ValueError: pass try: import unicodedata unicodedata.numeric(s) return True except (TypeError,ValueError): pass return False
def print_str(sample): for char in sample: print('U+%04x' % ord(char), # <1> char.center(6), # <2> 're_dig' if re_digit.match(char) else '-', # <3> ????????? 'isdig' if char.isdigit() else '-', # <4> ????? 'isnum' if char.isnumeric() else '-', # <5> ????? format(unicodedata.numeric(char), '5.2f'), # <6> ???????? unicodedata.name(char), # <7> ???????? sep='\t')
def test(self): data = (u'a', u'1', u' ', u'\u1234', u'\uFFFF') len_data = len(data) digit = unicodedata.digit numeric = unicodedata.numeric decimal = unicodedata.decimal category = unicodedata.category bidirectional = unicodedata.bidirectional decomposition = unicodedata.decomposition mirrored = unicodedata.mirrored combining = unicodedata.combining for i in xrange(self.rounds): c = data[i % len_data] digit(c, None) numeric(c, None) decimal(c, None) category(c) bidirectional(c) decomposition(c) mirrored(c) combining(c) digit(c, None) numeric(c, None) decimal(c, None) category(c) bidirectional(c) decomposition(c) mirrored(c) combining(c) digit(c, None) numeric(c, None) decimal(c, None) category(c) bidirectional(c) decomposition(c) mirrored(c) combining(c) digit(c, None) numeric(c, None) decimal(c, None) category(c) bidirectional(c) decomposition(c) mirrored(c) combining(c) digit(c, None) numeric(c, None) decimal(c, None) category(c) bidirectional(c) decomposition(c) mirrored(c) combining(c)