在使用齐道长的QTLibrary时,发现他定义的身份证生成的关键字方法并不能满足我的需求,
于是我在_element.py中重写了一个gen_idcard_new方法
import time import random import sys reload(sys) sys.setdefaultencoding('utf-8') def gen_idcard_new(self, idcard=''): """Get newidcard No. Example: | ${a}= | gen newidcard | 123 | It will return random idcard. like '111110198101010231'. """ ARR = (7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2) pro = { 0: '11', 1: '12', 2: '13', 3: '14', 4: '15', 5: '21', 6: '22', 7: '23', 8: '31', 9: '32', 10: '33', 11: '34', 12: '35', 13: '36', 14: '37', 15: '41', 16: '42', 17: '43', 18: '44', 19: '45', 20: '46', 21: '50', 22: '51', 23: '52', 24: '53', 25: '54', 26: '61', 27: '62', 28: '63', 29: '64', 30: '65' } LAST = { 0: '1', 1: '0', 2: 'x', 3: '9', 4: '8', 5: '7', 6: '6', 7: '5', 8: '4', 9: '3', 10: '2' } t = time.localtime()[0] x = '%02d%02d%02d%04d%02d%02d%03d' % (pro[random.randint(0, 30)], random.randint(01, 99), random.randint(01, 99), random.randint(t - 80, t - 18), random.randint(1, 12), random.randint(1, 28), random.randint(1, 999)) y = 0 for i in range(17): y += int(x[i]) * ARR[i] b = y % 11 return '%s%s' % (x, LAST[b])
完成后更新源文件,重新install即可看到新方法。
其中遇到了问题,python对格式缩进要求很严格,而一般编辑器对空格和tab的辨识度基本没有,
所以推荐一款python用的工具PyCharm
用户名:yueting3527
注册码: ===== LICENSE BEGIN =====
93347-12042010 00001FMHemWIs"6wozMZnat3IgXKXJ 2!nV2I6kSO48hgGLa9JNgjQ5oKz1Us FFR8k"nGzJHzjQT6IBG!1fbQZn9!Vi
===== LICENSE END =====