将数字词(例如,三百四十二)转换为数字(342)。
项目描述
Word to Number
这是一个Python模块,用于将数字词(例如,二十一个)转换为数字(21)。它可以处理从1到999,999,999,999(即十亿)范围内的正数。
安装
在安装word2number之前,请确保您已将pip更新到最新版本。
您可以使用以下命令使用Python包索引安装该模块。
pip install word2number
确保您已安装requirements.txt中给出的所有要求。
pip install -r requirements.txt
用法
首先,您需要使用以下代码导入模块。 .. code-block:: python
from word2number import w2n
然后,您可以使用 word_to_num 方法将数字词转换为数字,如下所示。
>>> print w2n.word_to_num("two million three thousand nine hundred and eighty four")
2003984
>>> print(w2n.word_to_num('two point three'))
2.3
>>> print(w2n.word_to_num('112'))
112
>>> print(w2n.word_to_num('point one'))
0.1
>>> print(w2n.word_to_num('one hundred thirty-five'))
135
>>> print(w2n.word_to_num('million million'))
Error: Redundant number! Please enter a valid number word (eg. two million twenty three thousand and forty nine)
None
>>> print(w2n.word_to_num('blah'))
Error: No valid number words found! Please enter a valid number word (eg. two million twenty three thousand and forty nine)
None
错误/故障
在安装word2number之前,请确保您已将pip更新到最新版本。
如果在上述代码的使用中您发现任何错误或漏洞,请通过Github提交问题。如果您不知道如何使用Github或通过它提交问题,我建议您学习它。否则,请发送一封包含可以重现问题的明确示例的电子邮件到akshay2626@gmail.com。
贡献者
Ben Batorsky (bpben)
Alex (ledovsky)
Tal Yarkoni (tyarkoni)
ButteredGroove (ButteredGroove)
项目详情
关闭
word2number-1.1.zip的哈希值
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 70e27a5d387f67b04c71fbb7621c05930b19bfd26efd6851e6e0f9969dcde7d0 |
|
MD5 | dcbd07346732407f86f33b0a811b74ff |
|
BLAKE2b-256 | 4a29a31940c848521f0725f0df6b25dca8917f13a2025b0e8fcbe5d0457e45e6 |