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

B

Bengt Richter

====< abspell.py >=======================================
# abspell.py v.10 20030806 17:20:23 Bengt Richter (e-mail address removed)
# 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top