abspell.py helps you say Hotel India -- as well as ticket locator codes ;-)

Bengt Richter bokr at oz.net
Thu Aug 7 04:45:29 CEST 2003

====< abspell.py >=======================================
# abspell.py v.10 20030806 17:20:23  Bengt Richter bokr at oz.net
# Use freely, so long as you accept that there is NO WARRANTY OF ANY KIND.
    Abspell translates alphanumeric strings to corresponding phonetic word codes.
    (see http://www.wikipedia.org/wiki/NATO_phonetic_alphabet)

Usage: abspell.py words and or digits to translate
abspell.py hello abspell v.10
Results in (untranslated letters are square bracketed):    
     hello = Hotel Echo Lima Lima Oscar
   abspell = Alpha Bravo Sierra Papa Echo Lima Lima
      v.10 = Victor [.] One Zero

abLetters = (
  'Alpha Bravo Charlie Delta Echo Foxtrot Golf Hotel India '
  'Juliet Kilo Lima Mike November Oscar Papa Quebec Romeo '
  'Sierra Tango Uniform Victor Whiskey Xray Yankee Zulu'
abDigits = 'Zero One Two Three Four Five Six Seven Eight Niner'.split()

def abSpell(s):
    if ' ' in s: return '\n'.join(map(abSpell, s.split()))
    return ' '.join(['%10s ='%s]+map(
        lambda c: c.isdigit() and abDigits[int(c)] or c.isalpha() and
            abLetters[ord(c.lower())-ord('a')] or '[%s]' %c, s))

if __name__ == '__main__':
    import sys
    if sys.argv[1:]:
        print abSpell(' '.join(sys.argv[1:]))
        print __doc__

Bengt Richter

More information about the Python-list mailing list