Created
June 13, 2014 17:15
-
-
Save Arkanosis/bea4ed990d66e2ff6f41 to your computer and use it in GitHub Desktop.
Script that converts a phone number to alternatives phone “words”
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# -*- coding: utf-8 -*- | |
import os | |
import sys | |
_num2char = [ | |
'0+ ', | |
'1 ', | |
'2ABC ', | |
'3DEF ', | |
'4GHI ', | |
'5JKL ', | |
'6MNO ', | |
'7PQRS', | |
'8TUV ', | |
'9WXYZ', | |
] | |
def tel2txt(tel): | |
tel = tel.replace(' ', '') | |
txt = '' | |
for line in xrange(5): | |
txt += '\n' | |
for num in tel: | |
txt += _num2char[int(num)][line] + '\t' | |
return txt[1:] | |
if __name__ == '__main__': | |
if len(sys.argv) != 2: | |
print >> sys.stderr, 'Usage: %s <number>' % sys.argv[0].split(os.sep)[-1] | |
sys.exit(1) | |
print tel2txt(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment