使用random模块,生成动态随机密码 分类: python 小练习 python Module 2013-12-04 17:23 278人阅读 评论(0) 收藏

生成动态随机密码:

import random,string

'''
length -- 指定密码的长度
chars  -- 指定密码有字母、数字、下划线及@、#组成
times  -- 指定一次生成的密码个数
'''
chars = string.lowercase+string.uppercase+''.join(map(str,range(10)))+'_@#'

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)



版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2013-12-04 17:23  前行者2011  阅读(119)  评论(0编辑  收藏  举报