#小练习 动态生成密码 分类: python 小练习 2013-08-15 16:25 314人阅读 评论(0) 收藏
import random,string
'''
length -- 指定密码的长度
chars -- 指定密码有字母、数字、下划线及@、#组成
times -- 指定一次生成的密码个数
'''
chars = string.lowercase+string.uppercase+''.join(map(str,range(9)))+'_@#'
def getpasswd(length = 6,times = 8,chars = chars):
for i in range(times):
print ''.join([random.choice(chars) for i in range(length)])
getpasswd()
getpasswd(length = 2,times=1) #指定生成一个长度为2的密码
'''
length -- 指定密码的长度
chars -- 指定密码有字母、数字、下划线及@、#组成
times -- 指定一次生成的密码个数
'''
chars = string.lowercase+string.uppercase+''.join(map(str,range(9)))+'_@#'
def getpasswd(length = 6,times = 8,chars = chars):
for i in range(times):
print ''.join([random.choice(chars) for i in range(length)])
getpasswd()
getpasswd(length = 2,times=1) #指定生成一个长度为2的密码
版权声明:本文为博主原创文章,未经博主允许不得转载。