Python生成随机密码

yipeiwu_com6年前Python基础

本人  python新手,使用的环境是python2.7,勿喷

复制代码 代码如下:

# -*- coding:utf8 -*-
import random
import string
import sys
reload(sys)
sys.setdefaultencoding("utf8")
def random_number():
    pwnumber=input("请输入需要密码个数:")
    pwlength=input("请输入需要密码长度:")
    if  pwlength<=10:
        for i in range(pwnumber):
            number=string.join(random.sample(string.digits+string.letters,pwlength)).replace(' ','')
            print number
    else :
        print "目前只支持10位以下密码,请重试!!"
        random_number()
if __name__=="__main__":
    random_number()

以上就是本文的全部内容了,希望对大家学习python能够有所帮助。

相关文章

Python按行读取文件的简单实现方法

1:readline() file = open("sample.txt") while 1: line = file.readline() if not line:...

小小聊天室Python代码实现

相对于Java方式的聊天室,Python同样可以做得到。而且可以做的更加的优雅。想必少了那么多的各种流的Python Socket,你一定会喜欢的。 至于知识点相关的内容,这里就不多说...

Django项目开发中cookies和session的常用操作分析

本文实例讲述了Django项目开发中cookies和session的常用操作。分享给大家供大家参考,具体如下: COOKIES操作 检查cookies是否存在: request.CO...

使用Python操作Elasticsearch数据索引的教程

使用Python操作Elasticsearch数据索引的教程

Elasticsearch是一个分布式、Restful的搜索及分析服务器,Apache Solr一样,它也是基于Lucence的索引服务器,但我认为Elasticsearch对比Solr...

Python学习资料

官方网站 : www.python.orgPython is an interpreted, interactive, object-oriented programming langu...