Converting integers to english representation

Martin Maney maney at
Wed Sep 8 20:40:07 CEST 2004

brianc at wrote:
> I'm developing a system to parse and enumerate addresses. The
> current obstacle is numbered streets. Does anybody know of a
> module already written to convert integers to their english
> equivalents?

The suggestion about searching for "ordinal" is good, but runs into all
those unicode false hits.  :-(

It isn't quite the same as either of your examples, and it goes only
one way, but this is what I'm using in one app where I want ordinalized
day numbers:

def _ord_sfx(decade):
    if decade != 1:
        return ('th', 'st', 'nd', 'rd', 'th', 'th', 'th', 'th', 'th', 'th')
    return ('th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th', 'th')

def ordinalize(n):
    decade = (n % 100) / 10
    unit = n % 10
    return '%d%s' % (n, _ord_sfx(decade)[unit])

If nature has made any one thing less susceptible than all others of
exclusive property, it is the action of the thinking power called an
idea, which an individual may exclusively possess as long as he keeps
it to himself; but the moment it is divulged, it forces itself into
the possession of every one, and the receiver cannot dispossess
himself of it.  -- Thomas Jefferson

More information about the Python-list mailing list