如何将unicode字符转换为Python中的浮点数? [英] How do I convert unicode characters to floats in Python?
问题描述
⅕将变成0.2
有关如何在Python中执行此操作的任何建议? / p>
您想使用 这将会打印: 如果该字符没有数字值, I am parsing a webpage which has Unicode representations of fractions. I would like to be able to take those strings directly and convert them to floats. For example: "⅕" would become 0.2 Any suggestions of how to do this in Python? You want to use the unicodedata module: This will print: If the character does not have a numeric value, then 这篇关于如何将unicode字符转换为Python中的浮点数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
import unicodedata
unicodedata.numeric(u'⅕ ')
0.20000000000000001
unicodedata.numeric(unichr [,默认值])
将会返回默认值,或者如果没有给出默认值,将会引发ValueError import unicodedata
unicodedata.numeric(u'⅕')
0.20000000000000001
unicodedata.numeric(unichr[, default])
will return default, or if default is not given will raise ValueError.