roman-numerals-py

4.1.0 · deprecated · verified Fri Apr 10

This package provides utilities for manipulating well-formed Roman numerals. It is currently at version 4.1.0 and is explicitly deprecated. Users are advised to switch to the `roman-numerals` package instead. The project seems to follow the release cadence of the main `roman-numerals` library.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic conversion from integers to Roman numerals and vice-versa, as well as handling invalid input. It uses the `RomanNumeral` class from the `roman_numerals` package, which is the underlying library for `roman-numerals-py`.

from roman_numerals import RomanNumeral, InvalidRomanNumeralError, OutOfRangeError

# Create a RomanNumeral from an integer
num_from_int = RomanNumeral(16)
print(f"Integer 16 as Roman: {num_from_int}") # Expected: XVI

# Create a RomanNumeral from a string
num_from_string = RomanNumeral.from_string("XVI")
print(f"Roman 'XVI' as Integer: {int(num_from_string)}") # Expected: 16

# Convert to uppercase/lowercase
print(f"'XVI' uppercase: {num_from_string.to_uppercase()}")
print(f"'XVI' lowercase: {num_from_string.to_lowercase()}")

# Handle invalid input
try:
    RomanNumeral.from_string("Spam!")
except InvalidRomanNumeralError as e:
    print(f"Caught expected error for 'Spam!': {e}")

try:
    RomanNumeral(0)
except OutOfRangeError as e:
    print(f"Caught expected error for 0: {e}")

view raw JSON →