python Roman number (PEP 313) class

Written for Roman class for python by Vernon Cole on 2009-12-24

The proposal to add Roman numeral literals to Python was presented on (nudge, nudge) April 1st, 2003 by Mike Meyers.
The PEP was rejected by BDFL due to (he said) differences of opinion as to proper syntax of Roman strings.
This submission is (really and truly) an implementation of PEP 313 as a module, in the spirit of the decimal module. The module is a demonstration of defining an object which is a subset of 'int'. It will accept integers, Arabic number string literals, or Roman string literals as the argument to its constructor. Due to the simplicity of its Roman-to-binary parser, it will accept almost any string which is understandable as a Roman number. For example str(roman.Roman('viiii')) will return 'IX'. To obtain lower case output, use .tolower(). I was disturbed by the limitations of existing Roman number algorithms which were limited to a range of 1 <= n < 4000. (A typical Roman legion consisted of 5300 to 6000 soldiers, so they must have been able to write large numbers.) A little research revealed the unicode code points for the larger digits. In the spirit of "explicit is better than implicit" I also added a representation for Zero -- the Latin word "Nulla" meaning "nothing." I think that it is better to print "nothing" than nothing, if you see what I mean. This module will operate in the range 0 <= n < 600000. A Python 3 version is included.

Read all announcements