Word2Number is a Python module, currently at version 1.1, designed to convert number words (e.g., 'three hundred and forty two') into their corresponding numeric digits (342). It supports positive numbers up to the billions (999,999,999,999). The library has an irregular release cadence, with updates addressing specific issues and improvements.
pip install word2numberVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import and use the `w2n.word_to_num` function for converting number words, including decimals and hyphenated numbers. It also shows how to handle potential `ValueError` exceptions for invalid inputs, which is the behavior introduced in version 1.1.
Ensure your project is running Python 3.x. Review code for Python 2 specific constructs (e.g., `print` statement) and update them to Python 3 standards.
Update error handling logic to catch `ValueError` exceptions instead of checking for `None` as a return value. For example, use a `try-except` block around `w2n.word_to_num()` calls.
Ensure input text represents positive numbers within the supported range. Implement preprocessing to handle or filter out unsupported inputs if necessary.
Clean and normalize input text to remove redundant or grammatically incorrect number word repetitions before passing them to `w2n.word_to_num()`.
pip install word2number
from word2number import w2n
number = w2n.word_to_num("one hundred and fifty")from word2number import w2n
number = w2n.word_to_num("twenty-seven")from word2number import w2n
# Ensure the input string is a valid number phrase
number = w2n.word_to_num("three hundred and fifty two")No dependency data recorded yet.