Python生成随机密码

yipeiwu_com5年前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函数式编程—高阶函数

详解Python函数式编程—高阶函数

函数式编程就是一种抽象程度很高的编程范式,纯粹的函数式编程语言编写的函数没有变量,因此,任意一个函数,只要输入是确定的,输出就是确定的,这种纯函数我们称之为没有副作用。而允许使用变量的程...

连接pandas以及数组转pandas的方法

pandas转数组 np.array(pandas) 数组转pandas pandas.DataFrame(numpy) pandas连接,只是左右接上,不合并值 df...

python实现提取百度搜索结果的方法

本文实例讲述了python实现提取百度搜索结果的方法。分享给大家供大家参考。具体实现方法如下: # coding=utf8 import urllib2 import string...

Python3之字节串bytes与字节数组bytearray的使用详解

字节串bytes 字节串也叫字节序列,是不可变的序列,存储以字节为单位的数据 字节串表示方法: b"ABCD" b"\x41\x42" ... 字节串的构造函数: bytes()...

python标准日志模块logging的使用方法

python标准日志模块logging的使用方法

最近写一个爬虫系统,需要用到python的日志记录模块,于是便学习了一下。python的标准库里的日志系统从Python2.3开始支持。只要import logging这个模块即可使用。...