跳转到主要内容

将数字词(例如,三百四十二)转换为数字(342)。

项目描述

travis_pic codecov_pic

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

贡献者

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。

源分布

word2number-1.1.zip (9.7 kB 查看哈希值)

上传时间

支持