python 随机数MD5加密及yield
Posted 3one
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 随机数MD5加密及yield相关的知识,希望对你有一定的参考价值。
# 随机数 生成验证码
import random
# print random.random()
# print random.randint(1, 5)
# print random.randrange(1, 5)
# temp = random.randint(65, 90)
# print chr(temp)
myList = []
for i in range(6):
i = random.randint(1, 3)
# print i
if i == 1:
temp = str(random.randint(1, 9))
myList.append(temp)
elif i == 2:
temp = random.randint(97, 122)
myList.append(chr(temp))
else:
temp = random.randint(65, 90)
myList.append(chr(temp))
print ‘‘.join(myList)
# md5加密
import hashlib
myHash = hashlib.md5()
myHash.update(‘admin‘)
print myHash.hexdigest()
#yield 用法
def AlexReadlines():
seek = 0
while True:
with open(‘C:\Users\dendei\Desktop\share\lock.txt‘,‘r‘) as f:
f.seek(seek)
data = f.readline()
if data:
seek = f.tell()
yield data
else:
return
#re = AlexReadlines()
for item in AlexReadlines():
print item
以上是关于python 随机数MD5加密及yield的主要内容,如果未能解决你的问题,请参考以下文章
实体字符转换,同样变量密码加盐MD5后生成的加密字符串不同解决办法 (原)