Skip to main content

Integer subset class using Roman numeral input and output

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

romanclass-1.0.1.zip (105.2 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page