Skip to content

Instantly share code, notes, and snippets.

@Arkanosis
Created June 13, 2014 17:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arkanosis/bea4ed990d66e2ff6f41 to your computer and use it in GitHub Desktop.
Save Arkanosis/bea4ed990d66e2ff6f41 to your computer and use it in GitHub Desktop.
Script that converts a phone number to alternatives phone “words”
#! /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