验证码生成
Posted shineriver
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了验证码生成相关的知识,希望对你有一定的参考价值。
‘验证码生成‘
import numpy
def list_connect(*lists): #
result=[]
try:
for i in lists:
assert isinstance(i, list),‘{}不是列表‘.format(i)
# if type(result)!=type(i): #判断入参是否均为列表,如果不是则抛出异常,中断程序
# raise TypeError(‘参数{}不是列表而是{}!‘.format(i,type(i)))
except AssertionError as t:
print(t)
else: #若均为列表则进行列表连接操作
for i in lists:
for j in range(len(i)):
result.append(i[j])
return result
# for i in lists:
# for j in range(len(i)):
# result.append(i[j])
def identifying_code(n):
num=[x for x in range(48,58)]
high_letter=[x for x in range(65,91)]
low_letter=[x for x in range(97,123)]
original_code=list_connect(num,high_letter,low_letter)
print(original_code)
check_code=numpy.random.randint(0,len(original_code),size=n)
result=‘‘
for i in check_code:
result=result+chr(original_code[i])
print(result)
if __name__ == ‘__main__‘:
# l1=[1,2,3,4]
# l2=[5,6,7]
print(list_connect(‘21‘,‘213‘))
# lt=list_connect(l1,l2)
# print(lt)
identifying_code(6)
print(chr(97))
以上是关于验证码生成的主要内容,如果未能解决你的问题,请参考以下文章