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. Advertisements

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.
Similar Threads
  1. nicholas

    dynamic map - store locator

    nicholas, Oct 19, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    446
    nicholas
    Oct 19, 2004
  2. Replies:
    0
    Views:
    529
  3. Replies:
    2
    Views:
    3,544
    Malcolm
    Aug 20, 2005
  4. jobs
    Replies:
    1
    Views:
    706
    Mark Rae [MVP]
    Sep 5, 2007
  5. Replies:
    0
    Views:
    793
  6. Replies:
    0
    Views:
    701
  7. Replies:
    0
    Views:
    655
  8. David A. Black
    Replies:
    2
    Views:
    354
    Tim Hunter
    Aug 19, 2004
Loading...