skip to navigation
skip to content

romanclass 1.0.1

Integer subset class using Roman numeral input and output

A "Roman" object is stored in the computer as a binary integer,
but it is displayed in Roman numerals.
(In technical terms, it is a subset of the built-in class int,
with a _str_() method which returns a Roman numeral string.)
[see PEP 313 for the inspiration]

This module has .toRoman() and .fromRoman() methods compatible with Mark Pilgrim's roman.py module, but has a larger range, a more forgiving parser, and allows construction of first class Roman objects.

Roman objects act very much like the built-in Decimal objects in Python,
they can be added, subtracted, multiplied, or divided and the result will be
another object of the same class.

So a programmer can say:

>>>import romanclass as roman

>>>two = roman.Roman(2)

>>>five = roman.Roman('V')

>>>print (two+five)

and the computer will print:

VII

This module uses unicode characters to support numbers in the range 0<=n<600000,
and has an optional .toUnicodeRoman() method which will output true unicode
character points for I V X L C D M (rather than their look-alike ASCII values)
and will output the points for I thru XII as single unicode code points.

The .toRoman() method [and the str() function] will output ASCII compatible
strings for values <= 3999.

The string "Nulla" [Latin for "nothing"] will be output for a zero value.

Out of range values will raise romanclass.OutOfRangeError

Badly formatted Roman numeral input strings will raise romanclass.InvalidRomanNumeralError in .fromRoman() or when initializing a Roman object.

CaesarCalc.py, A simple four-function Roman calculator is included as a test/demo.  
File Type Py Version Uploaded on Size
romanclass-1.0.1.zip (md5) Source 2010-08-12 102KB