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有点火? 给你7个学习它的理由!

最近Python有点火? 给你7个学习它的理由!

Python 是一门更注重可读性和效率的语言,尤其是相较于 Java,PHP 以及 C++ 这样的语言,它的这两个优势让其在开发者中大受欢迎。 诚然,它有点老了,但仍是80后啊 —— 至...

python中的编码知识整理汇总

问题 在平时工作中,遇到了这样的错误: UnicodeDecodeError: 'ascii' codec can't decode byte 想必大家也都碰到过,很常见 。于是...

Python3 实现串口两进程同时读写

通过两个进程分别读写串口,并把发送与接收到的内容记录在blog中,收到q时程序结束并退出 import threading,time import serial import str...

在Python中操作时间之mktime()方法的使用教程

 mktime()方法是localtime()反函数。它的参数是struct_time或全9元组,它返回一个浮点数,为了兼容时time()。 如果输入值不能表示为有效的时间,那...

对Python 语音识别框架详解

如下所示: from win32com.client import constants import os import win32com.client import pythonc...