Registry / serialization / word2number

word2number

JSON →
library1.1pypypi✓ verified 24d ago

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 word2number
INSTALL
IMPORT
SIG · WORD2NUMBER
W
word2number
serializationpythonv1.1
Install
2.3s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 2.3s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

w2n
from word2number import w2n

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.

from word2number import w2n # Basic conversion print(w2n.word_to_num("two million three thousand nine hundred and eighty four")) # Handling decimals print(w2n.word_to_num('two point three')) # With hyphens print(w2n.word_to_num('one hundred thirty-five')) # Direct digits (supported but not primary use-case) print(w2n.word_to_num('112')) # Example of an invalid input (will raise ValueError in v1.1+) try: print(w2n.word_to_num('blah')) except ValueError as e: print(f"Error: {e}")
Debug
Known issues
breakingVersions prior to 1.0 were primarily compatible with Python 2. Upgrading directly from very old versions to 1.0+ will require migrating Python 2 code to Python 3 syntax and semantics.
fix
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.
affects: <1.0
breakingIn version 1.1, the library changed its error handling for invalid inputs. Previously, it would print an error message to `stderr` and return `None`. Now, it `Raise`s a `ValueError`. Code that checked for `None` will break.
fix
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.
affects: 1.1
gotchaThe library is designed for positive numbers and has an upper limit of 999,999,999,999 (billions). It does not support negative numbers or numbers exceeding this range.
fix
Ensure input text represents positive numbers within the supported range. Implement preprocessing to handle or filter out unsupported inputs if necessary.
affects: All versions
gotchaInput phrases containing redundant number words (e.g., 'million million') will result in an error, as the library expects well-formed number phrases.
fix
Clean and normalize input text to remove redundant or grammatically incorrect number word repetitions before passing them to `w2n.word_to_num()`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'word2number'
The `word2number` package has not been installed in the current Python environment.
fix
pip install word2number
AttributeError: module 'word2number' has no attribute 'word_to_number'
After importing `word2number` as a module, the user tried to call a non-existent function directly on the module instead of using the `w2n` object's method.
fix
from word2number import w2n
number = w2n.word_to_num("one hundred and fifty")
TypeError: 'Word2Number' object is not callable
The `w2n` object (an instance of `Word2Number`) was imported and then erroneously called directly as if it were a function, instead of calling its `word_to_num` method.
fix
from word2number import w2n
number = w2n.word_to_num("twenty-seven")
ValueError: Unable to convert 'three hundred and fifty two hundred'
The input string provided to `word_to_num` contains non-numeric words, malformed number phrases, or a value the library cannot parse.
fix
from word2number import w2n
# Ensure the input string is a valid number phrase
number = w2n.word_to_num("three hundred and fifty two")
Upgrade
Version history
1.1latest on PyPI · released Jun 2, 2017
Audit
Dependencies

No dependency data recorded yet.

Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources
word2number — pip install word2number · libregistry