步骤就用代码里的注释描述算了, 直接上代码:
#!/usr/bin/env python2
#coding:utf-8
import sys
# 获取短信中心号码
if len(sys.argv) > 1:
orig = sys.argv[1]
else:
print "输入短信中心号码:",
orig = raw_input()
# 去掉+号
if orig[0] == "+":
orig = orig[1:]
# 不是偶数在后面加F
if len(orig) % 2 == 1:
orig = orig + "F"
# 把奇位和偶位互换
orig = "".join(["".join(x) for x in zip(orig[1::2],orig[::2])])
# 在号码前加91(国际化)+字符长度/2
orig = "91" + orig
orig = "%02d" % (len(orig)/2) + orig
print orig