Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > abspell.py helps you say Hotel India -- as well as ticket locator codes ;-)

Reply
Thread Tools

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

 
 
Bengt Richter
Guest
Posts: n/a
 
      08-07-2003
====< abspell.py >=======================================
# abspell.py v.10 20030806 17:20:23 Bengt Richter http://www.velocityreviews.com/forums/(E-Mail 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Website Design India - Web Design India Hyderabad - Web DesignServices India visioninfosyslinks@gmail.com HTML 0 12-20-2007 08:56 AM
Website Design India - Web Design India Hyderabad - Web DesignServices India visioninfosyslinks@gmail.com HTML 0 12-20-2007 08:54 AM
Website Design India - Web Design India Hyderabad - Web DesignServices India visioninfosyslinks@gmail.com HTML 0 12-20-2007 08:43 AM
Store Locator Feature? Distance between to Zip codes?? jobs ASP .Net 1 09-05-2007 09:19 PM



Advertisments