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

Discussion in 'Python' started by Bengt Richter, Aug 7, 2003.

  1. ====< abspell.py >=======================================
    # abspell.py v.10 20030806 17:20:23 Bengt Richter
    # 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
    e.g.,
    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'
    ).split()
    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:]))
    else:
    print __doc__
    =========================================================

    Regards,
    Bengt Richter
     
    Bengt Richter, Aug 7, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page