Converting integers to english representation

Cameron Laird claird at lairds.us
Thu Sep 9 18:08:05 EDT 2004


In article <chnjm7$56d$1 at wheel2.two14.net>,
Martin Maney  <maney at pobox.com> wrote:
>brianc at temple.edu 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])
			.
			.
			.
Those who want to pursue this deeper will probably read <URL:
http://cvs.sourceforge.net/viewcvs.py/snakelets/Snakelets/webapps/test/Attic/number.py >
and <URL: http://wiki.tcl.tk/591 >.



More information about the Python-list mailing list