{"id":4325,"library":"word2number","title":"Word2Number","description":"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.","status":"active","version":"1.1","language":"en","source_language":"en","source_url":"https://github.com/akshaynagpal/w2n","tags":["natural language processing","number conversion","utilities","nlp"],"install":[{"cmd":"pip install word2number","lang":"bash","label":"Install latest version"},{"cmd":"pip install word2number --upgrade","lang":"bash","label":"Upgrade to latest version"}],"dependencies":[],"imports":[{"symbol":"w2n","correct":"from word2number import w2n"}],"quickstart":{"code":"from word2number import w2n\n\n# Basic conversion\nprint(w2n.word_to_num(\"two million three thousand nine hundred and eighty four\"))\n\n# Handling decimals\nprint(w2n.word_to_num('two point three'))\n\n# With hyphens\nprint(w2n.word_to_num('one hundred thirty-five'))\n\n# Direct digits (supported but not primary use-case)\nprint(w2n.word_to_num('112'))\n\n# Example of an invalid input (will raise ValueError in v1.1+)\ntry:\n    print(w2n.word_to_num('blah'))\nexcept ValueError as e:\n    print(f\"Error: {e}\")","lang":"python","description":"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."},"warnings":[{"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.","message":"Versions 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.","severity":"breaking","affected_versions":"<1.0"},{"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.","message":"In 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.","severity":"breaking","affected_versions":"1.1"},{"fix":"Ensure input text represents positive numbers within the supported range. Implement preprocessing to handle or filter out unsupported inputs if necessary.","message":"The 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.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Clean and normalize input text to remove redundant or grammatically incorrect number word repetitions before passing them to `w2n.word_to_num()`.","message":"Input phrases containing redundant number words (e.g., 'million million') will result in an error, as the library expects well-formed number phrases.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-11T00:00:00.000Z","next_check":"2026-07-10T00:00:00.000Z"}