最近1年自学了python,发现python的应用场景挺多,自己百度了加自己稍微修改,写了段可以随时生成指定长度的安全随机密码

#C:\Python36

#coding=utf-8
import string
from random import choice
 
passwd_length = int(input('The length of password: '))        #密码的长度
passwd_count = int(input('The number of password lists: '))    #生成几组密码

symbols = '!@#$%&*+='                    #定义使用哪些特殊字符,可以自己定义修改

passwd_seed = string.digits + string.ascii_letters + symbols   #密码的类型定义,数字+字母+特殊字符,(如果使用string.punctuation是使用所有的特殊字符,包括'.',不好识别)

 
def generate_passwd():
    passwd = []
    while (len(passwd) < passwd_length):
        passwd.append(choice(passwd_seed))
    return ''.join(passwd)
      
if __name__ == '__main__':
    for i in range(0, passwd_count):
        print(generate_passwd())