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