生成随机密码


def NewPWD(length=16, handle_type=1):
   """
  生成随机密码
  当handle_type不为1时length则是无效的
  :param length: 密码长度
  :param handle_type: 默认:1,大小写字母+数字,其他则uuid生成的32位密码
  :return:
  """
   from random import choice
   import string
   if handle_type == 1:
       chars = string.ascii_letters + string.digits
       return ''.join([choice(chars) for i in range(length)])
   else:
       import uuid
       return str(uuid.uuid4()).replace("-", "")