471,311 Members | 1,731 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,311 software developers and data experts.

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

====< abspell.py >=======================================
# abspell.py v.10 20030806 17:20:23 Bengt Richter bo**@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
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
Jul 18 '05 #1
0 1228

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Sean Patterson | last post: by
2 posts views Thread by David Goodger | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.