zoukankan      html  css  js  c++  java
  • 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:UsersdendeiDesktopsharelock.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

  • 相关阅读:
    LeetCode 55
    LeetCode 337
    LeetCode 287
    LeetCode 274
    LeetCode 278
    LeetCode 264
    LeetCode 189
    LeetCode 206
    LeetCode 142
    LeetCode 88
  • 原文地址:https://www.cnblogs.com/3one/p/5543140.html
Copyright © 2011-2022 走看看