How do you read decimal digit values from multiple scripts?
decimal retrieves the integer value of a Unicode decimal digit and can return a supplied default for other characters.
Python example and interpretation
Arabic-Indic ٣ and fullwidth 3 both yield three, while Roman Ⅲ is outside the decimal-digit category. Enforce ASCII separately if an identifier protocol requires it.
from unicodedata import decimal
[decimal(c,None) for c in '٣3Ⅲ']Result [3, 3, None]
中文
如何从不同文字系统的十进制数字提取数值?
decimal 读取 Unicode 十进制数字的整数值,对其他字符可返回指定的默认值。
Python 算例与适用条件
阿拉伯印度数字 ٣ 和全角 3 都映射为 3,罗马数字 Ⅲ 不属于十进制数字。账户协议若只接受 ASCII,需另加限制。
from unicodedata import decimal
[decimal(c,None) for c in '٣3Ⅲ']结果 [3, 3, None]