本文整理汇总了Python中unicodedata.numeric方法的典型用法代码示例。如果您正苦于以下问题:Python unicodedata.numeric方法的具体用法?Python unicodedata.numeric怎么用?Python unicodedata.numeric使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类unicodedata
的用法示例。
在下文中一共展示了unicodedata.numeric方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ipy2_gh357
# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def test_ipy2_gh357(self):
"""https://github.com/IronLanguages/ironpython2/issues/357"""
import unicodedata
if is_cli:
self.assertEqual(unicodedata.name(u'\u4e2d'), '<CJK IDEOGRAPH, FIRST>..<CJK IDEOGRAPH, LAST>')
else:
self.assertEqual(unicodedata.name(u'\u4e2d'), 'CJK UNIFIED IDEOGRAPH-4E2D')
self.assertRaises(ValueError, unicodedata.decimal, u'\u4e2d')
self.assertEqual(unicodedata.decimal(u'\u4e2d', 0), 0)
self.assertRaises(ValueError, unicodedata.digit, u'\u4e2d')
self.assertEqual(unicodedata.digit(u'\u4e2d', 0), 0)
self.assertRaises(ValueError, unicodedata.numeric, u'\u4e2d')
self.assertEqual(unicodedata.numeric(u'\u4e2d', 0), 0)
self.assertEqual(unicodedata.category(u'\u4e2d'), 'Lo')
self.assertEqual(unicodedata.bidirectional(u'\u4e2d'), 'L')
self.assertEqual(unicodedata.combining(u'\u4e2d'), 0)
self.assertEqual(unicodedata.east_asian_width(u'\u4e2d'), 'W')
self.assertEqual(unicodedata.mirrored(u'\u4e2d'), 0)
self.assertEqual(unicodedata.decomposition(u'\u4e2d'), '')
示例2: convert_floats
# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def convert_floats(data, integers=None):
"""
Convert all numeric values in dictionary to float type.
"""
integers = integers or []
delete_keys = []
for key, value in data.iteritems():
try:
if isinstance(value, datetime.datetime):
continue
if is_number(value):
if key in integers:
data[key] = int(value)
else:
data[key] = float(value)
if math.isnan(data[key]):
delete_keys.append(key)
except:
pass
for key in delete_keys:
del data[key]
return data
示例3: is_number
# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
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
示例4: __IsNumber
# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def __IsNumber(self, input_data):
result = False
try:
float(input_data)
result = True
except ValueError:
pass
if result:
temp = float(input_data)
if np.isnan(temp):
return False
if np.isinf(temp):
return False
if not result:
try:
import unicodedata
unicodedata.numeric(input_data)
result = True
except (TypeError, ValueError):
pass
return result
示例5: is_number
# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
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
#----------------------------------------------------------------------
示例6: is_number
# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def is_number(s):
result = False
try:
float(s)
result = True
except ValueError:
pass
if not result:
try:
import unicodedata
unicodedata.numeric(s)
result = True
except (TypeError, ValueError):
pass
return result
示例7: is_number
# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
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
#----------------------------------------------------------------------
示例8: is_number
# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def is_number(s):
"""
Helper function to detect numbers
Args:
s: a string
Returns:
bool: True if s is a number
"""
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError):
pass
return False
示例9: is_number
# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def is_number(string):
"""Also accepts '.' in the string. Function 'isnumeric()' doesn't"""
try:
float(string)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(string)
return True
except (TypeError, ValueError):
pass
return False
示例10: isNumber
# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def isNumber(s):
"""
Determines if a unicode string (that may include commas) is a number.
:param s: Any unicode string.
:return: True if s represents a number, False otherwise.
"""
s = s.replace(',', '')
try:
float(s)
return True
except ValueError:
pass
try:
import unicodedata
unicodedata.numeric(s)
return True
except (TypeError, ValueError) as e:
pass
return False
示例11: is_number
# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
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
#主要程序部分
示例12: is_number
# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
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
#读取配置文件信息
示例13: is_number
# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
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
# Take image function
示例14: is_number
# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
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
########################################################################################################################
示例15: fraction_to_float
# 需要导入模块: import unicodedata [as 别名]
# 或者: from unicodedata import numeric [as 别名]
def fraction_to_float(fraction: str) -> float:
"""Convert string representation of a fraction to float.
Also supports unicode characters.
Args:
fraction (str): String representation of fraction, ie. "3/4", "1 1/2", etc.
Returns:
float: Converted fraction
"""
# For fractions with weird divider character (ie. "1⁄2")
fraction = fraction.replace("⁄", "/")
try:
# Convert unicode fractions (ie. "½")
fraction_out = unicodedata.numeric(fraction)
except TypeError:
try:
# Convert normal fraction (ie. "1/2")
fraction_out = float(sum(Fraction(s) for s in fraction.split()))
except ValueError:
# Convert combined fraction with unicode (ie. "1 ½")
fraction_split = fraction.split()
fraction_out = float(fraction_split[0]) + unicodedata.numeric(
fraction_split[1]
)
return fraction_out